前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >wordpress调用指定分类除外的置顶文章

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

作者头像
ytkah
发布2019-10-29 10:44:37
4940
发布2019-10-29 10:44:37
举报
文章被收录于专栏:ytkahytkahytkah

我们有时需要根据实际需要进行一些设置,比如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>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-10-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档