随机文章通常会显示在每篇文章的结尾或侧边栏,使文章内容更加充实,用户根据兴趣爱好自由选择。
添加随机文章代码如下
<?php global $post;
$postid = $post->ID;
$args = array(
'orderby' => 'rand',
'showposts'=>5,
'post__not_in'=>array($postid) );
query_posts($args);
echo '<ul>';
while (have_posts()) : the_post();
echo '<li><a href="'.get_permalink().'" title="'.the_title('','',false).'">'.the_title('','',false).'</a></li>';
endwhile;
echo '</ul>';
?>
代码说明:
‘post__not_in’=>array($postid) 代表随机显示的文章中会排除当前文章。
标签:WordPress 教程
不错,很实用的方法