WordPress下的默认排序是按照发布时间排序,但有时候,如果按修改时间排序来的比较合理,特别是有一些资料代码需要更改修正的时候。
下面,就说说已首页最新文章列表为例,修改成按修改时间排序。
wordpress的排序方式:
orderby=date 按发布日期排序
orderby=modified 按修改时间排序
orderby=ID 按文章ID排序
orderby=comment_count 按评论最多排序
orderby=title 按标题排序
orderby=rand 随机排序
用法
1、在首页的PHP文件中搜索
<?php while ( have_posts() ) : the_post(); ?>
2、在while 前面加上下面这段代码
$args = array(
'showposts' => 10,
'orderby' => modified,
);
query_posts($args);
然后保存,即可完成最新文章按修改时间排序。
或者使用以下的循环调用代码:
<?php if (have_posts()) : ?>
<?php query_posts('cat=117' . $mcatID. '&caller_get_posts=1&showposts=6&orderby=modified'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile;?>
<?php endif; wp_reset_query(); ?>
这篇博客介绍了如何将WordPress首页的文章列表设置为按修改时间排序,而非默认的发布时间排序。通过添加特定的PHP代码到主题文件中,可以实现按文章最后修改时间展示最新更新的内容,这对于经常需要更新资料的网站尤其有用。教程详细提供了两种实现方法,包括直接修改循环调用代码和使用query_posts函数。

214

被折叠的 条评论
为什么被折叠?



