wordpress最近修改更新的文章列表

你的文章是否会经常因为新的问题出现而改动呢?比如说wordpress知识随着版本的更新而变化,前端开发问题集锦等。

下面分享一个函数来自zww大叔的。

// Recently Updated Posts by zwwooooo | zww.me
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&offset=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><a href="'.get_permalink().'" title="'.$the_title_value.'">'
.$the_title_value.'</a><i>'
.get_the_modified_time('m.d').'</i></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>None data.</li>' : $recently_updated_posts;
echo $recently_updated_posts;
}

function clear_cache_zww() {
update_option('recently_updated_posts', ''); // 清空 recently_updated_posts
}
add_action('save_post', 'clear_cache_zww'); // 新发表文章/修改文章时触发更新

 

使用方法是在需要调用的地方添加下面这个函数:

<?php if ( function_exists('recently_updated_posts') ) recently_updated_posts(5,15); ?>

在里面也可以加上摘要之类的哦。只需要在函数里面添加摘要代码。有什么不懂的也可以咨询我们的qq群:324012906

声明: 未经本站许可,谢绝转载!

0 个主题帖 其中:热心观众:0 个, 管理员:0 个

抱歉,评论被关闭