^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助,如果有代码出错,请联系站长解决
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 腾讯云3年2核2G新品轻量限时特惠只需408元

WordPress前台展示最近更新的文章列表

WordPress 前台展示最近更新过的文章列表,可以将下面代码添加到 functions 文件中

function recently_updated_posts($num=10,$days=7) {  
//10 为展示文章数量,7 指 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', ''); 
}  
add_action('save_post', 'clear_cache_zww'); 

前台输出:

2 核 2G 限时特惠 396 元/3 年    宝塔建站 10850 大礼包

<h3>Recently Updated Posts</h3>  
<ul>  
<?php if ( function_exists('recently_updated_posts') ) recently_updated_posts(8,15); ?>  
</ul>  

赠人玫瑰,手有余香。