wordpress获取当前分类下的文章 single.php $current_cat_id = get_the_category()[0]->term_id; // 查询当前分类的文章 $args = array( ‘cat’ => $current_cat_id, ‘posts_per_page’ => 10 // 你想要显示的文章数量 ); $query = new WP_Query($args); if ($query->have_posts()) { echo ‘<

wordpress获取当前分类下的文章 single.php

$current_cat_id = get_the_category()[0]->term_id;

      // 查询当前分类的文章
      $args = array(
        'cat' => $current_cat_id,
        'posts_per_page' => 10 // 你想要显示的文章数量
      );

      $query = new WP_Query($args);

      if ($query->have_posts()) {
        echo '<div class="list-group single-list">';
        // 循环显示文章列表
        while ($query->have_posts()) {
          $query->the_post();
          echo '<a class="list-group-item" href="'%20.%20get_permalink()%20.%20'">' . get_the_title() . '</a>';
        }
        echo '</div>';
        // 重置查询
        wp_reset_postdata();
      }