调用同分类下的随机文章:添加到与文章内容页相关的模板,如single.php
area data-settings="dblclick" readonly ><?php$cat = get_the_category();foreach($cat as $key=>$category){$cat_id = $category->term_id;}$args = array('orderby' => 'rand','showposts' => 10,'cat' => $$cat_id );$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;?>area>123456789101112<?php$cat = get_the_category();foreach($cat as $key=>$category){$cat_id = $category->term_id;}$args = array('orderby' => 'rand','showposts' => 10,'cat' => $$cat_id );$query_posts = new WP_Query();$query_posts->query($args);while ($query_posts->have_posts()) : $query_posts->the_post();?><li><a href="<?php the_permal
ink(); ?>"><?php the_title(); ?></a></li><?php endwhile;?>
showposts后面的 10 是显示的文章数量
调用指定分类下的随机文章:
area data-settings="dblclick" readonly ><?php query_posts('showposts=10&cat=1&orderby=rand');while(have_posts()) : the_post();?><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php endwhile; ?>area>123456<?php query_posts('showposts=10&cat=1&orderby=rand');while(have_posts()) : the_post();?><a href="<?php the_permal
ink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php endwhile; ?>
cat后面的 1 是要调用的分类ID