【wordpress教程】首页文章随机显示实现方法

屏聚源码
屏聚源码
屏聚源码
3833
文章
50
评论
2019年9月2日15:36:38
评论
173,015

  如题,wordpress首页的文章随机显示,这样不仅仅可以增加了老文章的曝光率,而且在搜索蜘蛛来爬取网站的时候还会不断的发现网站首页在不断更新,这对于百度快照的更新是有一定帮助的。想到这点,难怪很多人都想要实现wordpress首页文章随机显示了。美菱阁精品网就来教大家实现这项wordpress技巧吧。

  1、打开你网站主题下的index.php文件。找到循环显示文章的代码位置。并找到以下代码:

  1.   while (have_posts()) :

  2.   或者

  3.   while ( have_posts() ) : the_post();

  将该代码修改成以下代码:

  1.   query_posts('orderby=rand');while ( have_posts() ) :

  2.   或者

  3.   query_posts('orderby=rand');while ( have_posts() ) : the_post();

  2、将下方代码

  1.   endwhile;

  修改成:

  1.   endwhile;wp_reset_query();

  这样基本就可以实现wordpress首页文章随机显示了。

  不过网上说该方法与插件wp-pagenavi发生冲突,导致网站无法翻页,如果你使用了这个插件,那就按照下方介绍的方法或者将该插件停止使用。

  将这个代码

  1.   query_posts('orderby=rand');while ( have_posts() ) :

  2.   或者

  3.   query_posts('orderby=rand');while ( have_posts() ) : the_post();

  修改成

  1.   $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

  2.   $args=array(

  3.   'orderby'=>rand,

  4.   'paged'=>$paged,

  5.   );

  6.   query_posts($args);

  7.   while (have_posts()) :

  怎么样?是不是觉得很简单。其实就是那么简单,上面的方法其实就是使用wordpress函数query_posts来控制文章输出方式。

继续阅读
屏聚源码
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: