我创建了自定义帖子,我想在我的网站中有一个页面显示最近的5个自定义帖子,如下所示:
<h1>Custom Posts 1</h1>
//show 5 of the most recent custom-posts-1 here
<h1>Custom Posts 2</h1>
//show 5 of the most recent custom-posts-2 here
我该怎么做?我查看了wordpress post模板文件,但我需要能够告诉我的页面要使用哪些帖子。我希望找到一个简单的函数,我只是添加到我的页面的编辑器(我启用它,所以我可以添加php)但我找不到合适的。
答案 0 :(得分:0)
我建议将两组帖子放在不同的WordPress类别中。
然后,您可以使用get_posts
拉回两个不同的列表,然后根据需要将其打印出来。
<?php
//A rough example
$posts = get_posts(array(
'numberposts' => 5,
'category_name' => 'custom-posts-2',
'orderby' => 'post_date',
'order' => 'DESC'
));
?>