Phpcms v9 calls the full-site article ranking implementation method

Source: Internet
Author: User
Tags foreach php file

V9 calls the current column line code as follows:

The code is as follows Copy Code
{pc:content action= "hits" catid= "$catid" num= "a" order= "views DESC" cache= "3600"}

Where $catid is the ID of the calling column, and if you want to implement a full station call, you need to modify the phpcmsmodulescontentclassescontent_tag.class.php file to find the following function:

The code is as follows Copy Code

/**
* List Label
* @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):

The code is as follows Copy Code

/**
* List Label
* @param $data
*/
Public function hits ($data) {
$catid = Intval ($data [' catid ']);

$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 (!empty ($catid) && $catid >0) {//Add judgment: ID is empty
if (! $this->set_modelid ($catid)) return false;
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, regardless of the set column ID 0 or empty, can be transferred to the entire station article ranking.

Call Method 1:

The code is as follows Copy Code
{pc:content action= "hits" catid= "0" num= "ten" order= "views DESC" cache= "3600"}

Call Method 2:

  code is as follows copy code

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

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.