Wordpress > 特定記事の表示方法

query_posts() を使用する場合

特定のカテゴリ(ID=3)「cat=3」の記事を1つ「showposts=1」表示します。
<?php query_posts('cat=3&showposts=1'); ?>
   <?php while (have_posts()) : the_post(); ?>
      <?php the_excerpt('Read the rest of this entry »'); ?>
   <?php endwhile; ?>
 

new WP_Query()を使用する場合

特定のID「page_id=2」の記事を1つ「showposts=1」表示します。
<?php $recent = new WP_Query("page_id=2&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
      <?php the_excerpt('Read the rest of this entry »'); ?>
<?php endwhile; ?>
 






最終更新:2013年02月04日 15:00