首页 WordPress之小工具根据评论热度获取文章前9篇文章

WordPress之小工具根据评论热度获取文章前9篇文章

沐辰客栈 2022-03-07 07:04:08 0 150
<ul class="My_Widget_zuixinpinglun">
  <?php 
  global $post;
  $i="1";$b="1";
     $post_num = 9; // 设置调用条数 
     $args = array( 
     'post_password' =>'',
     'post_status' => 'publish', // 只选公开的文章. 
     'post__not_in' => array($post->ID),//排除当前文章 
     'ignore_sticky_posts' => 1, // 排除置顶文章. 
     'orderby' => 'comment_count', // 依评论数排序. 
     'posts_per_page' => $post_num 
    ); 
      $query_posts = new WP_Query(); 
      $query_posts->query($args); 
      while( $query_posts->have_posts() ) { $query_posts->the_post(); $d=$i++; $c=$b++; if($d>3) $d=4; ?> 
<li ><span class="layui-badge bg-red-<?php echo $d; ?>"><?php echo $c; ?></span><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php  the_title(); ?></a></li> 
    <?php } wp_reset_query();?>
    </ul>


css · wordpress · js ·

发表评论