在wordpress后台-外观-编辑中打开index.php,在其中找到如下代码
<?php
if ( have_posts() ) :
/* Start the Loop */
while ( have_posts() ) :
the_post();
......
在<?php 前加入后
<?php $posts = query_posts($query_string . '&orderby=modified');?>
后更新文件,此时网站首页已经按照最后修改时间排序了。但此时,显示的时间仍是创建时间。显示时间的部分每个主题都不相同,这里是对twenty seventeen主题进行修改。该主题显示时间的函数叫做twentyseventeen_time_link(),定义在wordpress路径下的wp-content/themes/twentyseventeen/inc/template-tags.php中。在该文件中找到function twentyseventeen_time_link(),修改其中$time_string=sprintf(…); 为下面代码
$time_string = sprintf(
$time_string,
get_the_modified_data( DATE_W3C),
get_the_modified_data(),
get_the_date( DATE_W3C),
get_the_date()
};
更新好文件后刷新主页已经按照最后修改时间排序,并显示最后修改时间了