wordpress主题文章页面single模板或者边栏sidebar模板,调用同分类随机文章
随机文章可以促进网站内链建设,有利于阅读体验的SEO。
<ul>
<?php
$cat = get_the_category();
foreach($cat as $key=>$category){
$catid = $category->term_id;
}
$args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid );
$query_posts = new WP_Query();
$query_posts->query($args);
while ($query_posts->have_posts()) : $query_posts->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?>a>li>
<?php endwhile;?>
ul>
精选留言