2015-02-16 2 views
0

Я хочу показать содержимое своей страницы с помощью id или slug. Мне удалось сделать это в какой-то другой теме WP, но по какой-то причине он не работает на этот раз ...Страница запроса в wordpress slug/ID

Я хочу показать название, выдержку и признаки изображения

Это мой код:

<h1 class="text-center light-title"><?php echo the_title() ?></h1> 
          <span class="light-text"><?php the_excerpt(); ?></span> 
          <?php 
           if (has_post_thumbnail()) { // check if the post has a Post Thumbnail assigned to it. 
            the_post_thumbnail('full', array('class' => 'center-block img-responsive')); // show featured image 
           } 
          ?> 
           <?php 
            query_posts("page_id=222"); 
            while (have_posts()) : the_post() 
           ?> 
          <?php //the_content() ?> 
           <?php 
            endwhile; 
            wp_reset_query(); 
          ?> 
+0

Переместить ваш 'query_posts ("page_id = 222"); while (has_posts()): the_post() 'выше' the_tittle'. 'the_title(), the_post_thumbnail(), the_content()' должны находиться внутри цикла. В этом 'echo the_title()' вы не должны использовать echo на 'the_title()', это уже отображается без эха. Посетите [codex.wordpress.org] (http://codex.wordpress.org/Function_Reference/query_posts) –

ответ

2

Вы не говорите, что терпит неудачу, но порядок вашего кода кажется неправильным. the_title() и the_excerpt() обычно внутри цикл. Как это:

<?php 
    query_posts("page_id=222"); 
    while (have_posts()) : the_post() 
    ?> 
     <h1 class="text-center light-title"><?php echo the_title() ?></h1> 
     <span class="light-text"><?php the_excerpt(); ?></span> 
     <?php if (has_post_thumbnail()) { // check if the post has a Post Thumbnail assigned to it. 
       the_post_thumbnail('full', array('class' => 'center-block img-responsive')); // show featured image 
      } 
     ?> 
     <?php //the_content() ?> 
    <?php 
    endwhile; 
    wp_reset_query(); 
+0

это решило проблему для меня. Спасибо, bodbye! – pevoje

0

Использование WP_Query вместо query_posts даст вам больше контроля о масштабах:

<?php 
    $page = new WP_Query("page_id=374"); 
    while ($page->have_posts()) : $page->the_post(); 
    the_content(); 
    endwhile; 
?> 
Смежные вопросы