国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home CMS Tutorial PHPCMS What should I do if the order of phpcms related articles remains unchanged?

What should I do if the order of phpcms related articles remains unchanged?

Jun 10, 2020 am 09:41 AM

What should I do if the order of phpcms related articles remains unchanged?

#What should I do if the sorting of phpcms remains unchanged?

How to modify the problem of unchanged sorting of phpcms related articles:

Open phpcms/modules/content/classes/content_tag.class.php content model tag class , it is found that this tag will be sorted according to the order parameter only when the content has artificially set related readings. When the content does not have artificially set related readings, the query is performed based on keywords, but at this time, the order parameter is not sorted. Instead, it is not sorted. This is why the related readings called by articles are always so old.

The method to correct this problem is as follows:
Modify the phpcms/modules/content/classes/content_tag.class.php content model tag class file, and modify the relation method in the content_tag class to :

The code is as follows:

/**
* 相關(guān)文章標簽
* @param $data
*/
public function relation($data) {
$catid = intval($data['catid']);
if(!$this->set_modelid($catid)) return false;
$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 = $this->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 = $this->db->select($sql2, '*', $limit, $order,'','id');
$number += count($r);
foreach ($r as $id=>$v) {
if($i<= $data[&#39;limit&#39;] && !in_array($id, $key_array)) $key_array[$id] = $v;
$i++;
}
if($data[&#39;limit&#39;]<$number) break;
}
}
if($data[&#39;id&#39;]) unset($key_array[$data[&#39;id&#39;]]);
return $key_array;
}

In fact, it is just $r = $this->db->select($sql2, '*', $limit, '','', 'id'); replaced by $r = $this->db->select($sql2, '*', $limit, $order,'','id'); and let the order parameter be passed into the query method.
In the template, use the following tags and add the order parameter to achieve sorting.

The code is as follows:

{pc:content action="relation" relation="$relation" id="$id" catid="$catid" num="5" keywords="$rs[keywords]" order="id DESC"}
{loop $data $r}
{/loop}
{/pc}

If you are a mysophobic friend and are worried that directly modifying the PC will affect future upgrades, you can extract it separately. Put it in the template and use it as a function. The code is as follows:

The code is as follows:

<?php
/**
* 內(nèi)容模型 - 相關(guān)文章標簽(修正排序異常問題)
* @param $data
*/
function mk1_content_tag_relation($data) {
$db = pc_base::load_model(&#39;content_model&#39;);
$catid = intval($data[&#39;catid&#39;]);
$siteids = getcache(&#39;category_content&#39;,&#39;commons&#39;);
if(!$siteids[$catid]) return false;
$siteid = $siteids[$catid];
$category = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);
if(empty($category)) return false;
if($category[$catid][&#39;type&#39;]!=0) return false;
$db->set_model($category[$catid][&#39;modelid&#39;]);
$order = $data[&#39;order&#39;];
$sql = "`status`=99";
$limit = $data[&#39;id&#39;] ? $data[&#39;limit&#39;]+1 : $data[&#39;limit&#39;];
if($data[&#39;relation&#39;]) {
$relations = explode(&#39;|&#39;,trim($data[&#39;relation&#39;],&#39;|&#39;));
$relations = array_diff($relations, array(null));
$relations = implode(&#39;,&#39;,$relations);
$sql = " `id` IN ($relations)";
$key_array = $db->select($sql, &#39;*&#39;, $limit, $order,&#39;&#39;,&#39;id&#39;);
} elseif($data[&#39;keywords&#39;]) {
$keywords = str_replace(&#39;%&#39;, &#39;&#39;,$data[&#39;keywords&#39;]);
$keywords_arr = explode(&#39; &#39;,$keywords);
$key_array = array();
$number = 0;
$i =1;
foreach ($keywords_arr as $_k) {
$sql2 = $sql." AND `keywords` LIKE &#39;%$_k%&#39;".(isset($data[&#39;id&#39;]) && intval($data[&#39;id&#39;]) ? " AND `id` != &#39;".abs(intval($data[&#39;id&#39;]))."&#39;" : &#39;&#39;);
$r = $db->select($sql2, &#39;*&#39;, $limit, $order,&#39;&#39;,&#39;id&#39;);
$number += count($r);
foreach ($r as $id=>$v) {
if($i<= $data[&#39;limit&#39;] && !in_array($id, $key_array)) $key_array[$id] = $v;
$i++;
}
if($data[&#39;limit&#39;]<$number) break;
}
}
if($data[&#39;id&#39;]) unset($key_array[$data[&#39;id&#39;]]);
return $key_array;
}
?>

In the template, use the following PHP code to obtain it.

The code is as follows:

{php $data = mk1_content_tag_relation(array(&#39;relation&#39;=>$relation,&#39;id&#39;=>$id,&#39;catid&#39;=>$catid,&#39;keywords&#39;=>$rs[&#39;keywords&#39;],&#39;order&#39;=>&#39;id DESC&#39;,&#39;limit&#39;=>&#39;4&#39;)); }
{loop $data $r}
{/loop}

In fact, it is just a small problem. The PC should be corrected in the future. The above method is provided to those anxious webmaster friends.

Recommended tutorial: "PHP Video Tutorial"

The above is the detailed content of What should I do if the order of phpcms related articles remains unchanged?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276