wordpress当前分类下随机文章调用代码

2024年09月21日 建站教程

wordpress建站如何利用代码调用随机当前分类下文章?下面web建站小编给大家介绍一下同分类随机文章的调用方法!

代码如下:

<?php
  $cat = get_the_category();
  foreach($cat as $key=>$category){
  $catid = $category->term_id;}
  $args = array('orderby' => 'rand','showposts' => 10,'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(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
  
  <?php endwhile;?>
  <?php wp_reset_query(); ?>

本文链接:http://so.lmcjl.com/news/13577/

展开阅读全文
相关内容