我们在调整WordPress程序调用文章的时候,可能会有见过调用最新文章、热门文章,以及多少天热度文章的列表。但是,如果有一些文章是我们早期更新的,近期如果有变动重新编辑过的,这类的文章也是有需要重弄新作为编辑文章调用出来,这样可以告知用户这篇文章已经更新。

**第一、调用脚本**

> // 最近修改和编辑的文章
> function recently_updated_posts($num=10,$days=7) {
> if( !$recently_updated_posts = get_option('recently_updated_posts') ) {
> query_posts('post_status=publish&orderby=modified&posts_per_page=-1');
> $i=0;
> while ( have_posts() && $i<$num ) : the_post();
> if (current_time('timestamp') - get_the_time('U') > 60*60*24*$days) {
> $i++;
> $the_title_value=get_the_title();
> $recently_updated_posts.='<li><i class="icon-cai"></i><a href="'.get_permalink().'" title="最终修改于'.get_the_modified_time('Y.m.d G:i').'">'
> .$the_title_value.'</a></li>';
> }
> endwhile;
> wp_reset_query();
> if ( !empty($recently_updated_posts) ) update_option('recently_updated_posts', $recently_updated_posts);
> }
> $recently_updated_posts=($recently_updated_posts == '') ? '<li>请拭目以待.</li>' : $recently_updated_posts;
> echo $recently_updated_posts;
> }
> function clear_cache_zww() {
> update_option('recently_updated_posts', '');
> }
> add_action('save_post', 'clear_cache_zww');

将代码放到当前主题的Functions.php文件中。

**第二、调用模块**

> <?php if ( function_exists('recently_updated_posts') ) recently_updated_posts(8,30); ?>

数字8表示调用八篇,30表示30天内修改编辑过的。数字可以根据实际调整。