
WordPress Twenty Fifteen 主题模板,
在首页就是要显示 1 篇帖子,
但是,在分类页,默认也只显示 1 篇帖子,这不符合需求。所以要改为显示 5 条摘要。
修改的方法:
1、列表页由全文显示改为摘要显示的方法,
编辑器打开 /wp-content/themes/twentyfifteen/ 目录下的 archive.php 文件,
查找以下代码:get_template_part( ‘content’, get_post_format() );
替换成以下代码:get_template_part( ‘content-search’, get_post_format() );
其实就是将这两个文件此代码中的content改为content-search

2、阅读设置,为 1

3、加入代码到 function.php
首页就是 1 篇帖子。
分类页设置为 5 的话,这段代码没有 bug,
但是如果是 10 的话,则侧栏的最新帖子那块,显示10条就有点长了。
function iteblog_posts_per_page($query) { $is_home = $query->get('is_home'); if($is_home){ $query->set('posts_per_page', 1); } if(is_search()){ $query->set('posts_per_page',-1);//搜索页显示所有匹配的文章,不分页 } if(is_archive()){ $query->set('posts_per_page',5);//archive每页显示25篇文章 } if(empty($is_home)){ if (is_category()) { $query->set('posts_per_page', 5); } if (is_tag()) { $query->set('posts_per_page', 5); } //endif } } //function add_action('pre_get_posts', 'iteblog_posts_per_page');
