马春杰杰 Exit Reader Mode

[mcj]WordPress修改右侧小工具文章按照修改时间排序

WordPress中,可以通过orderby进行排序,orderby支持的排序方法有:

所以为了让文章可以按照修改时间进行排序,首先打开widgets/widget-posts.php文件,然后修改:

<label>
    排序:
    <select style="width:100%;" id="<?php echo $this->get_field_id('orderby'); ?>" name="<?php echo $this->get_field_name('orderby'); ?>" style="width:100%;">
        <option value="comment_count" <?php selected('comment_count', $instance['orderby']); ?>>评论数</option>
        <option value="views" <?php selected('views', $instance['orderby']); ?>>浏览量</option>
        <option value="date" <?php selected('date', $instance['orderby']); ?>>更新时间</option>
        <option value="rand" <?php selected('rand', $instance['orderby']); ?>>随机</option>
    </select>
</label>

将第6行的date改为modified,然后修改:

<li><a<?php echo _post_target_blank() ?> href="<?php the_permalink(); ?>"><?php if( $img ){echo '<span class="thumbnail">'; echo _get_post_thumbnail(); echo '</span>'; }else{$img = '';} ?><span class="text"><?php the_title(); ?><?php echo get_the_subtitle() ?></span><span class="muted"><?php the_time('Y-m-d');?></span><?php if( $comn ){ ?><span class="muted"><?php echo '评论(', comments_number('0', '1', '%'), ')'; ?></span><?php } ?></a></li>

将其中的the_time('Y-m-d');修改为the_modified_date();

效果如下:

本文最后更新于2023年6月6日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!