随身笔记
随身笔记

wordpress编辑更新后的老文章重新返回显示在首页

使用了wordpress程序建立个人网站的过程中都会不断的想完善自己的网站功能但是往往对于那些不会写后台代码的站长来说要添加新的功能模块只能上搜索引擎上疯狂的找类似的功能了,这次小编就遇到了一个想添加的功能但是怎么也找不到最好还是找到了,功能效果是这样的,我们之前发布的老文章多少也会有添加或者修改的地方,但是不想仅仅添加或者修改就结束掉,这样让浏览者下次来访的时候同时也发现不了所以想办法让添加或者修改的文章重新显示返回到首页中去,这样我们干脆添加一个新的栏目专门存放一些被添加或者修改的老文章。

1,添加以下代码到 functions.php文件中:

[code]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><a href=”‘.get_permalink().'” title=”‘.$the_title_value.'”>’
.$the_title_value.'</a><span class=”updatetime”><br />» 修改时间: ‘
.get_the_modified_time(‘Y.m.d G:i’).'</span></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’); // 新发表文章/修改文章时触发更新[/code]

2.可以使用下面的函数调用:

[code]<h3>Recently Updated Posts</h3>
<ul>
<?php if ( function_exists(‘recently_updated_posts’) ) recently_updated_posts(8,15); ?>
</ul>[/code]

参数说明:8 为展示文章数量,15 指15天内发表的文章除外

没有标签
首页      前端资源      wordpress教程      wordpress编辑更新后的老文章重新返回显示在首页

随身笔记

wordpress编辑更新后的老文章重新返回显示在首页
使用了wordpress程序建立个人网站的过程中都会不断的想完善自己的网站功能但是往往对于那些不会写后台代码的站长来说要添加新的功能模块只能上搜索引擎上疯狂的找类似的功能了,这次小编…
扫描二维码继续阅读
2013-03-18