Phpcms V9 How to call the whole station article rank

Source: Internet
Author: User

Want to add browsing ranking function on the homepage, but found that PHPCMS is not supported to call the entire station article ranking. Carefully studied the Phpcms source code, finally found a solution.

By default, PHPCMS only supports calling the current article rank, the code is as follows:

{pc:content action= "hits" catid= "$catid" num= "order=" views DESC "cache=" 3600 "}

Where $catid is the ID of the column to be called, if you want to implement the full station call, you need to modify the phpcms\modules\content\classes\content_tag.class.php file, find the following function:

/**

* Leaderboard Tags

* @param $data

*/

Public function hits ($data) {

$catid = Intval ($data [' catid ']);

if (! $this->set_modelid ($catid)) return false;

$this->hits_db = Pc_base::load_model (' Hits_model ');

$sql = $desc = $ids = ";

$array = $ids _array = Array ();

$order = $data [' Order '];

$hitsid = ' C '. $this->modelid. ' -%‘;

$sql = "Hitsid like ' $hitsid '";

if (Isset ($data [' Day ')]) {

$updatetime = Sys_time-intval ($data [' Day ']) *86400;

$sql. = "and updatetime> ' $updatetime '";

}

if ($this->category[$catid [' child ']) {

$catids _str = $this->category[$catid] [' Arrchildid '];

$pos = Strpos ($catids _str, ', ') +1;

$catids _str = substr ($catids _str, $pos);

$sql. = "and catid in ($catids _str)";

} else {

$sql. = "and catid= ' $catid '";

}

$hits = Array ();

$result = $this->hits_db->select ($sql, ' * ', $data [' limit '], $order);

foreach ($result as $r) {

$pos = Strpos ($r [' Hitsid '], '-', 2) + 1;

$ids _array[] = $id = substr ($r [' Hitsid '], $pos);

$hits [$id] = $r;

}

$ids = Implode (', ', $ids _array);

if ($ids) {

$sql = "status=99 and ID in ($ids)";

} else {

$sql = ";

}

$this->db->table_name = $this->tablename;

$result = $this->db->select ($sql, ' * ', $data [' limit '], ' ', ' ', ' id ');

foreach ($ids _array as $id) {

if ($result [$id] [' title ']!= ') {

$array [$id] = $result [$id];

$array [$id] = Array_merge ($array [$id], $hits [$id]);

}

}

return $array;

}

Modify the code (see note):

/**

* Leaderboard Tags

* @param $data

*/

Public function hits ($data) {

$catid = Intval ($data [' catid ']);


if (!empty ($catid) && $catid >0) {//Add judgment: ID is empty

if (! $this->set_modelid ($catid)) return false;

}

$this->hits_db = Pc_base::load_model (' Hits_model ');

$sql = $desc = $ids = ";

$array = $ids _array = Array ();

$order = $data [' Order '];

$hitsid = ' C '. $this->modelid. ' -%‘;

$sql = "Hitsid like ' $hitsid '";

if (Isset ($data [' Day ')]) {

$updatetime = Sys_time-intval ($data [' Day ']) *86400;

$sql. = "and updatetime> ' $updatetime '";

}

if (!emptyempty ($catid) && $catid >0) {//Add judgment: ID is empty

if ($this->category[$catid [' child ']) {

$catids _str = $this->category[$catid] [' Arrchildid '];

$pos = Strpos ($catids _str, ', ') +1;

$catids _str = substr ($catids _str, $pos);

$sql. = "and catid in ($catids _str)";

} else {

$sql. = "and catid= ' $catid '";

}

}

$hits = Array ();

$result = $this->hits_db->select ($sql, ' * ', $data [' limit '], $order);

foreach ($result as $r) {

$pos = Strpos ($r [' Hitsid '], '-', 2) + 1;

$ids _array[] = $id = substr ($r [' Hitsid '], $pos);

$hits [$id] = $r;

}

$ids = Implode (', ', $ids _array);

if ($ids) {

$sql = "status=99 and ID in ($ids)";

} else {

$sql = ";

}

$this->db->table_name = $this->tablename;

$result = $this->db->select ($sql, ' * ', $data [' limit '], ' ', ' ', ' id ');

foreach ($ids _array as $id) {

if ($result [$id] [' title ']!= ') {

$array [$id] = $result [$id];

$array [$id] = Array_merge ($array [$id], $hits [$id]);

}

}

return $array;

}

After modifying the code, regardless of the Set column ID of 0 or empty, can be adjusted to the entire station article ranking.

Call Method 1:

{pc:content action= "hits" catid= "0" num= "ten" order= "views DESC" cache= "3600"}

Call Method 2:

{pc:content action= "hits" num= "ten" order= "views DESC" cache= "3600"}

Phpcms V9 How to call the whole station article rank

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.