wordpress收费下载资源主题
wordpress付费下载资源插件

wordpress 获取自定义分类法里排除某个分类的(顶置)文章列表

最近给客户加了个论坛功能,需要帖子顶置功能,可是又不想某版块下的顶置贴显示在论坛首页,所以得在首页排除掉某版块的顶置贴,大致代码如下:

$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 );

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情