WordPress侧边栏显示最近修改/更新过的文章

2013-11-20  付民 

调用最近修改过的文章的方法代码实现法

1. 把下面的函数代码扔到主题的 functions.php

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // 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'); $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>' .$the_title_value.'<span class="updatetime"><br />&raquo; 修改时间: ' .get_the_modified_time('Y.m.d G:i').''; } 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.' : $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'); // 新发表文章/修改文章时触发更新

2. 调用,如在侧边栏

1 2 3 4 <h3>Recently Updated Posts <ul> <?php if ( function_exists('recently_updated_posts') ) recently_updated_posts(8,15); ?>

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

插件实现法

WP-RecentlyUpdatedPosts Widget 插件激活后是以小工具方式显示最近修改更新过的一些老文章,让访者知道你更新了文章内容,方便查看关注。适合一些需要不定期更新内容的文章,如下载资源、开源项目发布等共享类文章。

Plugin name: WP-RecentlyUpdatedPosts Widget

Version: 0.1

Author: zwwooooo

features:

  • 可以自定义最近修改的文章数量
  • 自定义排除多少天内的新文章(默认排除7天内的新文章)
  • 数据库缓存方式,更新/修改文章/设置小工具时更新缓存。

下载地址Google code

安装方法:

  1. 把 wp-recentlyupdatedposts-widget.0.1.zip 上传到 /wp-content/plugins 目录下并解压
    Optional: 直接去“WP后台 》插件 》安装插件 》上传
  2. 去“WP后台 》插件”激活插件 WP-RecentlyUpdatedPosts Widget
  3. 然后去“WP后台 》外观 》小工具”,找到小工具“最近更新的文章”,拉到右边的小工具栏即可。

510°/5101 人阅读/0 条评论 发表评论

登录 后发表评论