自定义首页和feed的排序

WP默认的排序方式系最新到最旧,不过有旧的文章如果改过,真系没人知。

改下首页同FEED的排序,有利于俾其它人/嘢知道,分类同TAG就算了,阅读习惯问题。

呢度用到的系WP的 query_posts 函数,详细用法可以睇Function Reference/query posts

呢次的目标系以最后修改时间来排序显示首页同FEED,好简单,代码就得两行:

global $query_string;
query_posts($query_string . "&orderby=modified");

系主循环前添加,while (have_posts())前边,下边详细讲。

1,要系首页以最后修改时间来排序,要改主题的index.php,揾主循环,例如:

<?php if (have_posts()) : ?>    <?php while (have_posts()) : the_post();。。。后略。。。

呢度改成

<?php
global $query_string;
query_posts($query_string . "&orderby=modified");
while (have_posts()) : the_post();
。。。后略。。。

呢种方法可以有后续自定义,就系可以直接系网址输入query_posts的参数,例如:

http://WP域名/?order=asc

你唔会有写几种排序连接冲动啊嘛。。。

2,改FEED的输出排序以最后修改时间来定

function bluedream_atom_rss_head()
{
	global $query_string;
	query_posts($query_string . "&orderby=modified");
}

add_action( 'rdf_header', 'bluedream_atom_rss_head' );
add_action( 'atom_head', 'bluedream_atom_rss_head' );
add_action( 'rss_head', 'bluedream_atom_rss_head' );
add_action( 'rss2_head', 'bluedream_atom_rss_head' );

直接加到主题的functions.php就得。

PHP