我正在使用插件“自定义帖子类型”创建一个基于问题的杂志,其中我的类型之一是“封面”每一期都会有一个这样的帖子,包括封面和文章列表。我的问题是,如何使主页默认显示这种类型的最新帖子的单个视图?
使主页成为自定义帖子类型的最新帖子
1 个回复
最合适的回答,由SO网友:s_ha_dum 整理而成
创建front-page.php
在主题中归档并查询您的帖子类型的最新帖子。
$args = array(
\'post_type\' => \'yourtypename\',
\'posts_per_page\' => 1,
\'ignore_sticky_posts\' => true,
\'post_status\' => \'publish\',
}
$latest = new WP_Query($args);
if ($latest->have_posts()) {
while ($latest->have_posts()) {
$latest->the_post();
the_title();
// etc
}
}
请参见Template Hierarchy 有关“自动”加载的文件的信息。。结束