特定カテゴリのみピックアップ
たとえばトップページにトピックス(ID:15)のみ日付と記事タイトルを5件表示させたい。
そんなときは、home.phpに
<table> <?php $posts = get_posts('numberposts=5&category=15'); global $post; ?> <?php if($posts): foreach($posts as $post): setup_postdata($post); ?> <tr> <th><?php the_time('Y.m.d'); ?></th> <td><a href="<?php the_permalink();?>"><?php the_title(); ?></a></td> </tr> <?php endforeach; endif; ?> </table>
the_dateだと、同じ日付の記事が複数あった場合、最新の記事にしか日付が表示されないので注意。
昇順・降順は変更できる。