为了在我的wordpress博客上显示每个类别的最后5篇博文,我需要编写什么PHP代码?
我只想包含博客文章的标题,作者的日期和名称(博客文章中没有图片)。
我想要做的一个例子就是在这个主题中,名为'XXXXX CATEGORY中的最新帖子' http://sponsoredwp.info/brightness/
谢谢!
答案 0 :(得分:0)
首先,您想了解一下get_categories函数:
http://codex.wordpress.org/Function_Reference/get_categories
然后你应该看一下get_posts函数:
http://codex.wordpress.org/Template_Tags/get_posts
一个小例子:
$args = array('orderby' => 'name','order' => 'DESC');
foreach(get_categories($args) as $category)
{
//Here you want to print out a header for your category
$my_query = new WP_Query('category_id='.$category->id.'&showposts=1');
while($my_query->have_posts()):
$my_query->the_post();
//Here you want to use the functions like the_title() and the_permlink()
//So you can itterate you results
endwhile;
}