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