在製作樣板時,首頁部份常會遇到需要讀取特定分類文章的問題,
只要使用query_posts函式即可自由控制要讀取的文章及數量。
<?php
query_posts('showposts=5&cat=3'); //讀出5篇分類ID為3的文章
while (have_posts()) : the_post(); //讀取文章的迴圈
?>
<?php
/*
the_permalink()為文章內頁連結
the_title()為文章標題
the_time()為日期
*/
?>
<h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
<small ><?php the_time('l, F jS, Y') ?></small>
<?php endwhile; ?>