WordPress主题开发:按分类调用文章

调用catid为2的分类下的文章,就是后台分类链接的tag_ID

<?php
$cat_query = new WP_Query(array(
    'cat' => '2'
        ));
?>
<div id="sitebar">
    <ul class="nav nav-pills nav-stacked nav-og">
        <?php
        if ($cat_query->have_posts()) : while ($cat_query->have_posts()) : $cat_query->the_post();
                ?>
                <li><a href=“<?php the_permalink() ?>” target=“_blank” title=“<?php the_title(); ?>”><?php the_title(); ?></a></li>
            <?php endwhile; ?>
        <?php endif; ?>
    </ul>
</div>   

 获取当前分类id

get_query_var('cat')

猜你喜欢

转载自www.cnblogs.com/tinyphp/p/6390285.html
今日推荐