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