那么这样只能通知到一个用户,并且还是一个肯留言的用户,其他的不留言的,看见链接失效了也是抱着懒得管的态度,
这里有没有版本在前端或者指定位置调用一个列表,专门显示最新修改过的文章呢?
这样以来既可以通知给所有人,也可以添加一个内链和老文章的展示次数,当然如果你想让你的老文章有更多的展示机会,
可以看看这个随机文章的功能:WordPress随机浏览文章功能
如何添加最新修改过的文章列表
首先还是给wordpress的主题的function.php添加以下功能代码:
// 最近编辑过的文章 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'); ///修改文章时触发清空缓存
然后在前端页面展示的地方添加调用代码:
<ul> <?php if ( function_exists('recently_updated_posts') ) recently_updated_posts(7,35); ?> </ul>
其中代码中的7表示调用七篇,35表示在35天之内编辑过的文章。
这个WordPress调用最新修改过的文章列表功能是带有缓存的,只有后台重新编辑文章之后才会清除缓存,这就节省了许多数据库查询工作,前台完全是静态展示。
请登录之后再进行评论