Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the ranking of related articles in phpcms remains unchanged

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article uses easy-to-understand examples to introduce how to solve the problem of constant sorting of phpcms related articles, the code is very detailed, interested friends can refer to, I hope it can be helpful to you.

The modification method of the ranking invariant problem of phpcms related articles:

Open the phpcms/modules/content/classes/content_tag.class.php content model tag class and find that the tag is sorted according to the order parameter only if the content has artificially set relevant readings. When there is no artificial related reading, the query is made by keyword, but it is not sorted by the order parameter. Instead, it does not sort. This is why the relevant reading invoked by the article is always so old.

The ways to correct the problem are as follows:

Modify the phpcms/modules/content/classes/content_tag.class.php content model label class file, and modify the relation method in the content_tag class to:

The code is as follows:

/ * related article tags * @ 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 = str_replace ('%','', $data [keywords']) 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 ($iselect ($sql2,'*', $limit, 'id'); replace with $r = $this- > db- > select ($sql2,' *', $limit, $order,'','id') Let the order parameter be passed into the query method.

In the template, the sorting can be achieved by using the following tag and the order parameter.

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 have a friend who is addicted to cleanliness and are worried that directly modifying PC will affect future upgrades, you can extract it separately. Put it into the template to use as a function. The code is as follows:

The code is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report