7B2主题修改圈子话题按评论时间排序

这个功能源自B2主题老版本,后来被春哥更改为权重算法排序了。

新版本已经更新为按照权重算法排序,此处我懒得改这几个字,所以实际上是按照评论时间排序

7B2主题修改圈子话题按评论时间排序

教程

b2/Modules/Common/circle.php,原代码如下

        //根据评论时间排序
        $order_by = b2_get_option('circle_topic','topic_order_by',$circle_id);

        if($order_by === ''){
            $order_by = b2_get_option('circle_topic','topic_order_by');
        }

        if($order_by == 'comment'){
            $meta_query['comment_update'] = array(
                array(
                    'key' => 'b2_hotness'
                )
            );
        }

        if($circle_id === $default_circle_id){

            $meta_query['current_circle'] = array(
                array(
                    'key'     => 'b2_currentCircle',
                    'compare' => 'NOT EXISTS'
                )
            );
        }

        $meta_query['relation'] = 'AND';
        if($order_by == 'comment' && isset($data['order_by']) && $data['order_by'] !== 'comment'){
            $args['orderby'] = 'meta_value';
            $args['order'] = array('comment_update'=>'DESC');
        }

        $args['meta_query'] = $meta_query;

        if($circle_id && $circle_id !== $default_circle_id){
            $args['tax_query'] = array(
                array(
                    'taxonomy' => 'circle_tags',
                    'field' => 'term_id',
                    'terms' => $circle_id
                )
            );

        }

将以上代码修改为下面的代码。

//根据评论时间排序-www.xingkongweb.com/60151.html
$order_by = b2_get_option('circle_topic','topic_order_by',$circle_id);

if($order_by === ''){
$order_by = b2_get_option('circle_topic','topic_order_by');
}

if($order_by == 'comment'){
$meta_query['comment_update'] = array(
'relation' => 'OR',
array(
'key' => 'b2_comment_update'
),
array(
'key' => 'b2_comment_update',
'compare' => 'NOT EXISTS'
)
);
}


$meta_query['relation'] = 'AND';
if($order_by == 'comment' && $data['order_by'] !== 'comment'){
$args['orderby'] = 'meta_value_num';
$args['meta_type'] = 'NUMERIC';
$args['order'] = 'DESC';
}
$args['meta_query'] = $meta_query;

if($circle_id === $default_circle_id){
if(!isset($args['meta_query'])){
$args['meta_query'] = array(
'relation' => 'AND'
);
}

array_push($args['meta_query'],
array(
'key' => 'b2_currentCircle',
'compare' => 'NOT EXISTS'
)
);
}

if($circle_id && $circle_id !== $default_circle_id){
$args['tax_query'] = array(
array(
'taxonomy' => 'circle_tags',
'field' => 'term_id',
'terms' => $circle_id
)
);

}

再到后台切换时,权重排序就变成了评论时间排序了字没变,但是功能变了

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索