最近给客户加了个论坛功能,需要帖子顶置功能,可是又不想某版块下的顶置贴显示在论坛首页,所以得在首页排除掉某版块的顶置贴,大致代码如下:
$sticky = get_option('sticky_posts'); rsort( $sticky );
$sticky_args = array('post__in' => $sticky, 'caller_get_posts' => 1, 'showposts' => 10, 'post_type' => 'thread',
'tax_query' => array(
array(
'taxonomy' => 'forum',
'terms' => array('145','146','147','148','149','150'),
'field' => 'id',
'operator' => 'NOT IN'
)
)
);
$sticky_arms = array_merge($sticky_args, $wp_query->query);
query_posts($sticky_arms);
while (have_posts()) : the_post();
get_template_part( 'content-thread' );
endwhile; wp_reset_query();
顺便贴上自定义文章类型分类筛选代码:
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'order' => $order,
'meta_key' => '_thumbnail_id'
);
if ($category != '0') {
$args['tax_query'] = array (
array(
'taxonomy' => 'portfolio_categories',
'field' => 'id',
'terms' => $category
)
);
}
$portfolio_items = get_posts( $args );
原文链接:https://www.dqzy.cn/2025/05/20/668.html,转载请注明出处。
1、本站所有源码资源(包括源代码、软件、学习资料等)仅供研究学习以及参考等合法使用,请勿用于商业用途以及违法使用。如本站不慎侵犯您的版权请联系我们,我们将及时处理,并撤下相关内容!
2、访问本站的用户必须明白,本站对所提供下载的软件和程序代码不拥有任何权利,其版权归该软件和程序代码的合法拥有者所有,请用户在下载使用前必须详细阅读并遵守软件作者的“使用许可协议”,本站仅仅是一个学习交流的平台。
3、如下载的压缩包需要解压密码,若无特殊说明,那么文件的解压密码则为:www.dqzy.cn。
4、点启资源网是一个免费且专业分享网站源码、图片素材、特效代码、教程文章、站长工具的平台。我们努力给站长提供好的资源!


评论0