WordPress で指定したカテゴリの記事を指定した数だけテーブルで一覧にします。
記事数が指定した数に達しない場合でも、内容の無い行を出力します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <table cellspacing="0" class="top_news" width="100%"> <?php $i=0; $numberposts=5; $myposts = get_posts("numberposts={$numberposts}&category=1,3"); foreach($myposts as $post) { $cat = get_the_category(); $cat = $cat[0]; echo '<tr>'; echo '<th>' . get_the_time('Y年m月d日') . '</th>'; echo '<td>' . $cat->cat_name . '</td>'; echo '<td><a href="' . get_permalink() . '">' . get_the_title() . '</a></td>'; echo '</tr>'; $i++; } while($i<$numberposts) { echo '<tr><th height="38"></th><td></td><td></td></tr>'; $i++; } ?> </table> |
コメント