最近给客户加了个论坛功能,需要帖子顶置功能,可是又不想某版块下的顶置贴显示在论坛首页,所以得在首页排除掉某版块的顶置贴,大致代码如下:
1 |
$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(); |
顺便贴上自定义文章类型分类筛选代码:
1 |
$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 ); |
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。