phpcms v9关联文章排序陈旧问题的修改方法
/**
* 内容模型 - 相关文章标签(修正排序异常问题)
* @param $data
*/
function mk1_content_tag_relation($data) {
$db = pc_base::load_model('content_model');
$catid = intval($data['catid']);
$siteids = getcache('category_content','commons');
if(!$siteids[$catid]) return false;
$siteid = $siteids[$catid];
$category = getcache('category_content_'.$siteid,'commons');
if(empty($category)) return false;
if($category[$catid]['type']!=0) return false;
$db->set_model($category[$catid]['modelid']);
$order = $data['order'];
$sql = "`status`=99";
$limit = $data['id'] ? $data['limit']+1 : $data['limit'];
if($data['relation']) {
$relations = explode('|',trim($data['relation'],'|'));
$relations = array_diff($relations, array(null));
$relations = implode(',',$relations);
$sql = " `id` IN ($relations)";
$key_array = $db->select($sql, '*', $limit, $order,'','id');
} elseif($data['keywords']) {
$keywords = str_replace('%', '',$data['keywords']);
$keywords_arr = explode(' ',$keywords);
$key_array = array();
$number = 0;
$i =1;
foreach ($keywords_arr as $_k) {
$sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
$r = $db->select($sql2, '*', $limit, $order,'','id');
$number += count($r);
foreach ($r as $id=>$v) {
if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;
$i++;
}
if($data['limit']<$number) break;
}
}
if($data['id']) unset($key_array[$data['id']]);
return $key_array;
}
?>
本站资源均来自互联网或会员发布,如果不小心侵犯了您的权益请与我们联系。我们将立即删除!谢谢!