Wordpress > 特定記事の表示方法

「Wordpress/特定記事の表示方法」の編集履歴(バックアップ)一覧に戻る

Wordpress/特定記事の表示方法 - (2013/02/04 (月) 14:59:49) のソース

**query_posts() を使用する場合
特定のカテゴリ(ID=3)「cat=3」の記事を1つ「showposts=1」表示します。
#highlihgt(){{
<?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」表示します。
#highlihgt(){{
<?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; ?>}}