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


上一篇:响应式图像–图片自适应大小

下一篇:wordpress置顶文章不改变文章排序的方法


Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器