wordpress 伪更新

让你的Wordpress博客持续保持更新,这种更新是属于伪更新,它只是随机把你的发表过的文章显示在首页第一篇。
放fuctions中,不过在代码倒数第二行放入你主题index.php中loop循环中的东西而已,原理也比较简单。

<code>
  function randomtopicfornoupdate($count = 24) {  //如果不传递时间参数,默认为24小时  
  global $wpdb;  
  $last = $wpdb->get_results("SELECT MAX(post_date) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' ) AND (post_status = 'publish' )");  
  $laststamp = strtotime($last[0]->MAX_m);  
  $hours = (time()+3600*8 - $laststamp)/3600;  
  if( $hours > $count) {  //如果当前时间距离最后一次更新文章的时间已经超过指定的时间,则执行伪更新  
      if((time()+3600*8 - get_option("rtfu_time"))/3600 > $count) {  
        update_option("rtfu_time",time()+3600*8);  
        $rand_query = new WP_Query("showposts=1&orderby=rand");  
        if($rand_query->have_posts()){  
            while($rand_query->have_posts()){  
                $rand_query->the_post();  
                global $id;  
                update_option("rtfu_postid",$id);  
                show_the_index();  
            }  
        }  
      }   
      else {  
          $rndpostid = get_option("rtfu_postid");  
          $rand_query = new WP_Query("p=" .$rndpostid);  
          if($rand_query->have_posts()){  
            while($rand_query->have_posts()){  
                $rand_query->the_post();  
                show_the_index();  //调用主题的式样显示随机的这篇文章  
            }  
        }  
  
      }  
  }  
}   
function show_the_index() {?> 

//此处是调用主题首页blog的式样,根据自己的主题调整。基本上是把index.php里的内容搬过来就可以了。 

} </code>

把下面的代码放到大循环的外部,即把

<code>//括号里的单位是小时,即如12小时内没有新文章的话,则执行伪更新随机调用一篇已发布的文章放在首页第一篇文章
if(function_exists('randomtopicfornoupdate')) randomtopicfornoupdate(12);</code>

放到

<code><?php if (have_posts()) : while (have_posts()) : the_post(); ?></code>

的前面。

0 thoughts on “wordpress 伪更新
添加一条新回复 回到顶部

亲爱的,主人已经关闭了这篇文章的评论 。