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

Modia 自媒体 wordpress主题

0 条评论

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

联系我们
近期站长大婚,Erphpdown插件、Modia主题、Modown主题、Moshou主题、Mohtml主题限时优惠