免费《新手做网站视频教程》,在线观看,如果你想从零开始自己做网站,点击开始吧!

WordPress 分类页 category 获取当前分类下所有文章

  1. 首页
  2. »
  3. 图文教程
  4. »
  5. WordPress建站教程
  6. »
  7. WordPress 分类页 category 获取当前分类下所有文章

文章目录

<?php
        // 获取当前分类下所有文章
        $args = array(
            'category__in' => $cat,  // 显示指定分类。cat可以在category页直接得到分类ID
            'order' => 'DESC',
        );
        // 下面这一行代码是必须的,不然不能分页
        $arms = array_merge($args, $wp_query->query);
        query_posts($arms);
        if (have_posts()) :
            while (have_posts()) : the_post(); update_post_caches($posts); ?>
                <?php get_template_part('template/category-li')?>
            <?php endwhile; else : ?>
            <li>暂无文章</li>
        <?php endif; wp_reset_query();  ?>

推荐阅读

联系我