您需要创建或编辑模板,以便以特定方式显示所有帖子。您调整的设置对于WordPress显示内容的位置没有足够的指导,提要设置只调整RSS提要,而不是实际的面向访问者的URL。
第一:如果您还没有子主题,请创建一个子主题。这样,当父主题更新时,您不会丢失更改。
下一步:决定是否真的希望所有帖子都出现在某个页面上(即http://example.com/all-posts/) 或者如果你希望他们出现在你的主页上(即。http://example.com/). 默认情况下,主页已经查询了您网站上的帖子,因此,除非您需要主页上的不同功能,否则建议在此处显示所有帖子。这样,您只需稍微修改数据库查询,而不是“获取5篇文章”,您会说“获取所有文章”,而在页面上,您会说“获取所有文章”,而不是“获取这一页”。
然后:在子主题中,创建front-page.php
用于主页或tpl-all-posts.php
您可以选择任何页面。这是一个文件,它将控制要显示所有帖子的特定URL的输出。在文件中,您可能希望首先复制父主题的index.php
其中包含尽可能简单的循环。
然后,要告诉该页面您需要所有帖子,而不仅仅是一个有限的帖子集,您需要创建一个functions.php
子主题中的文件。如果选择主页,可以添加以下内容:
// use the Pre Get Posts hook that modifies the main database query
add_action(\'pre_get_posts\', \'wpse_modify_query\');
function wpse_modify_query($query) {
// Replace the main query on the homepage
if($query->is_main_query() && !is_admin() && $query->is_home()) {
// Setting posts per page to -1 gets them all
$query->set(\'posts_per_page\', \'-1\');
}
}
或者,如果选择了页面,请更改条件:
// use the Pre Get Posts hook that modifies the main database query
add_action(\'pre_get_posts\', \'wpse_modify_query\');
function wpse_modify_query($query) {
// Replace the main query on the homepage
// Change the last part (\'all-posts\') to whatever your Page\'s slug is
if($query->is_main_query() && !is_admin() && $query->is_page(\'all-posts\')) {
// Setting posts per page to -1 gets them all
$query->set(\'posts_per_page\', \'-1\');
}
}
这将给你所有的帖子,无论你选择哪一页。然后,在模板文件中,可以调整循环。您可能想使用
the_excerpt()
而不是
the_content()
这将只提取部分帖子内容,并添加您需要的“阅读更多”链接。如果摘录长度不符合您的喜好,可以使用过滤器更改其长度,如果您想使其更便于屏幕阅读,可以使用过滤器更改“阅读更多”链接。
从那里,你可以打电话get_post_meta()
要获取Posteta,然后需要确定如何显示它,要包含哪些HTML等。