2015-02-17 4 views
0

У меня статическая страница в блоге Wordpress. Я не буду перечислять последний заголовок сообщения в выбранной области на всех других страницах. Поэтому у меня есть этот код.Список названий блога на пользовательской странице

<?php 

     $args = array(
      'showposts' => '1' 
     ); 
     $the_query = new WP_Query($args); 

     if ($the_query->have_posts()) { 

     ?> 

      <header> 
       <h2 class="latestPost"><a href="#"><?php the_title(); ?></a></h2> 
      </header> 

     <?php 

     } else { 
      // no posts found 
     } 
     wp_reset_postdata(); 

     ?> 

Это не отображает последний заглавный пост, как я wan't, он отображает название страницы посетитель находится в.

Что я делаю неправильно?

ответ

4

Попробуйте как этот

$args = array(
     'showposts' => '1' 
    ); 

    $the_query = new WP_Query($args); 
    // The Loop 
    if ($the_query->have_posts()) { 
      $the_query->the_post(); ?> 
      <header> 
      <h2 class="latestPost"><a href="#"><?php the_title(); ?></a></h2> 
      </header> 
     <?php 
    } else { 
     // no posts found 
    } 
    /* Restore original Post Data */ 
    wp_reset_postdata(); 
+0

Это работал, спасибо Видьи! –

+0

Добро пожаловать –

0
<?php query_posts('showposts=1'); ?> 
<?php if (have_posts()) : the_post(); ?> 

<header> 
    <h2 class="latestPost"><a href="#"><?php the_title(); ?></a></h2> 
</header> 
<?php 

    } else { 
     // no posts found 
    } 

?> 
+0

Использование 'query_posts', вероятно, не самый лучший вариант: http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs -get-сообщений – Hobo