WordPress 调用同分类或指定某分类下的随机文章
调用同分类下的随机文章:添加到与文章内容页相关的模板,如single.php
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%20the_permalink();%20?>"><?php the_title(); ?></a></li><?php endwhile;?>
showposts后面的 10 是显示的文章数量
调用指定分类下的随机文章:
123456<?php query_posts('showposts=10&cat=1&orderby=rand');while(have_posts()) : the_post();?><a href="<?php%20the_permalink();%20?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php endwhile; ?>
cat后面的 1 是要调用的分类ID
上一篇:响应式图像–图片自适应大小
webacc.exe是什么文件?webacc.exe是不是病毒
WINSYS.vbs是什么文件?WINSYS.vbs是不是病毒
winssh.exe是什么文件?winssh.exe是不是病毒
wt.exe是什么文件?wt.exe是不是病毒
winsysetm.exe是什么文件?winsysetm.exe是不是病毒
winstrve.exe是什么文件?winstrve.exe是不是病毒
winsysupd7.exe是什么文件?winsysupd7.exe是不是病毒
winsysupd.exe是什么文件?winsysupd.exe是不是病毒
winsysupd2.exe是什么文件?winsysupd2.exe是不是病毒
winsysupd8.exe是什么文件?winsysupd8.exe是不是病毒