在主题目录下找到存档页面文件,存档页面包括index.php、archive.php等,一般分类页、标签页、日期页和作者页等都是用archive.php。
确定了你要控制哪个页面的文章列表,那么我们就可以开始了,比如你想让首页的文章按评论数排序,那么index.php中的代码基本框架就是这样的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php // query_posts函数query_posts('orderby=comment_count'); // 主循环if ( have_posts() ) : while ( have_posts() ) : the_post(); ..endwhile; else: ..endif; // 重置querywp_reset_query(); ?> |
其实你要做的就是在index.php中查找
或 ,在前面添加query_posts函数即可。不过以上方式可能会导致首页无法分页,那你可以将query_posts函数改成这样的行式:1 2 3 4 5 6 7 8 | // 下面这一行代码是必须的,不然你的首页不能分页$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;$args = array( // 这里以下面的方式添加query_posts参数,具体参数可以参加官方文档 'orderby' => comment_count, 'paged' => $paged);query_posts($args); |
Copyright © 2013-2021 8a.hk All Rights Reserved. 八艾云 版权所有 中山市八艾云计算有限公司 粤ICP备14095776号