wordpress调用指定分类除外的置顶文章

我们有时需要根据实际需要进行一些设置,比如wordpress调用指定分类除外的置顶文章,如何实现呢?随ytkah一起来看看吧,用如下代码插入到需要调取的位置

<div class="recommended-container">
    <div class="title"><strong>RECOMMENDED</strong></div>
    <div class="box">
        <ul>
            <?php
            $args = array(
                'post_type' => 'post',
                'showposts' => 3,
//                'orderby' => 'rand',
                'post__in' => get_option('sticky_posts'),//获取置顶文章
                'cat' => array(-36,-37,-38),//排除指定分类id
            );
            $my_query = new WP_Query($args);
            if( $my_query->have_posts() ) {
                while ($my_query->have_posts()) : $my_query->the_post(); ?>
                    <li>
                        <a href="<?php the_permalink(); ?>">
                            <?php the_post_thumbnail( array(88,88) ); ?>
                            <strong><?php the_title();?></strong>
                        </a>
                    </li>
                <?php endwhile; wp_reset_query(); } ?>
        </ul>
    </div>
</div>

  

猜你喜欢

转载自www.cnblogs.com/ytkah/p/11739766.html