如题,wordpress首页的文章随机显示,这样不仅仅可以增加了老文章的曝光率,而且在搜索蜘蛛来爬取网站的时候还会不断的发现网站首页在不断更新,这对于百度快照的更新是有一定帮助的。想到这点,难怪很多人都想要实现wordpress首页文章随机显示了。美菱阁精品网就来教大家实现这项wordpress技巧吧。
1、打开你网站主题下的index.php文件。找到循环显示文章的代码位置。并找到以下代码:
-
while (have_posts()) :
-
或者
-
while ( have_posts() ) : the_post();
将该代码修改成以下代码:
-
query_posts('orderby=rand');while ( have_posts() ) :
-
或者
-
query_posts('orderby=rand');while ( have_posts() ) : the_post();
2、将下方代码
-
endwhile;
修改成:
-
endwhile;wp_reset_query();
这样基本就可以实现wordpress首页文章随机显示了。
不过网上说该方法与插件wp-pagenavi发生冲突,导致网站无法翻页,如果你使用了这个插件,那就按照下方介绍的方法或者将该插件停止使用。
将这个代码
-
query_posts('orderby=rand');while ( have_posts() ) :
-
或者
-
query_posts('orderby=rand');while ( have_posts() ) : the_post();
修改成
-
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
-
$args=array(
-
'orderby'=>rand,
-
'paged'=>$paged,
-
);
-
query_posts($args);
-
while (have_posts()) :
怎么样?是不是觉得很简单。其实就是那么简单,上面的方法其实就是使用wordpress函数query_posts来控制文章输出方式。
评论