最新の記事一覧をこんなコードで表示します。

  <?php query_posts(‘showposts=10′); ?>
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <li>
   <a href=”<?php the_permalink() ?>”><?php the_title() ?></a>
  </li>
  <?php endwhile; endif; ?>

1.php query_posts(‘showposts=10′) :

  表示する記事数を設定します。
  showposts= の後に数字を指定します。

2.php if (have_posts()) : while (have_posts()) : the_post(); ?>

 これ見ると分かりますけど、index.phpに必ずある 記事表示用のコードです。 そのまんまパクリ。

3.<a href=”<?php the_permalink() ?>”><?php the_title() ?></a>

 php the_title() で記事のタイトルのみを表示するように指定しています。 投稿日時も表示したい場合には、<?php the_date(); ?>や<?php the_time(); ?>等を追加します。

 これを例えば、下の様なコードで表示させたい場所に加えます。

 <h2>Recently</h2>
 <ul>
  <?php query_posts(‘showposts=10′); ?>
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <li>
   <a href=”<?php the_permalink() ?>”><?php the_title() ?></a>
  </li>
  <?php endwhile; endif; ?>
 </ul>

 上のコードを使用したサイトの例。 『ESTO*』sidebarで使ってます。

内容が近い??過去の記事:

  1. WordPress ロゴ
  2. WordPress.com
  3. WordPress
  4. 翻訳 – WPL Codex for WordPress 1
  5. WordPress Plug-ins 翻訳中