Feb
28
2009

トップページに最近の投稿リストを表示

9:44 am

タイトルのとおり、トップページに直近の投稿リスト(5件)を表示するスクリプトです。
わざわざ、news ページに行かなくてもどんな投稿があったか分かるというものです。
作成した top_page.php に以下を追記します。

<li><h2>最近の投稿</h2>
    <ul>
<?php
$lastposts = get_posts('numberposts=5');
foreach($lastposts as $post) :
    setup_postdata($post);
 ?>
    <li><?php the_time('Y.m.d'); ?> <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
    </ul>
</li>

タイトルに news へのリンクを張りました。また、リストだけでなく記事の概要も付け加えました。

    <li><h2><a href="http://www.hbirds.net/news">最近の投稿</a></h2>
    <ul>
     <?php
     $lastposts = get_posts('numberposts=5');
     foreach($lastposts as $post) :
     setup_postdata($post);
     ?>
    <li><?php the_time('Y.m.d'); ?> <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li>
    <?php the_excerpt();?>
    <?php endforeach; ?>
    </ul>
    </li>

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

www.hbirds.net