当前位置:首页 > CMS教程 > phpcms > 列表

Phpcms V9 调用全站最新文章的代码

发布:smiling 来源: PHP粉丝网  添加日期:2014-10-19 22:28:23 浏览: 评论:0 

Phpcms默认不支持调用全站最新文章,需要修改文件\phpcms\modules\content\classes\content_tag.class.php,找到以下函数:

  1. public function lists($data) {  
  2.          $catid = intval($data['catid']);  
  3.          if(!$this->set_modelid($catid)) return false;  
  4.          if(isset($data['where'])) {  
  5.              $sql = $data['where'];  
  6.          } else {  
  7.              $thumb = intval($data['thumb']) ? " AND thumb != ''" : '';  
  8.              if($this->category[$catid]['child']) {  
  9.                  $catids_str = $this->category[$catid]['arrchildid'];  
  10.                  $pos = strpos($catids_str,',')+1;  
  11.                  $catids_str = substr($catids_str$pos);  
  12.                  $sql = "status=99 AND catid IN ($catids_str)".$thumb;  
  13.              } else {  
  14.                  $sql = "status=99 AND catid='$catid'".$thumb;  
  15.              }  
  16.          }  
  17.          $order = $data['order'];  
  18.    
  19.          $return = $this->db->select($sql'*'$data['limit'], $order'''id');  
  20.                            
  21.          //调用副表的数据  
  22.          if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {  
  23.              $ids = array();  
  24.              foreach ($return as $v) {  
  25.                  if (isset($v['id']) && !emptyempty($v['id'])) {  
  26.                      $ids[] = $v['id'];  
  27.                  } else {  
  28.                      continue;  
  29.                  }  
  30.              }  
  31.              if (!emptyempty($ids)) {  
  32.                  $this->db->table_name = $this->db->table_name.'_data';  
  33.                  $ids = implode('\',\''$ids);  
  34.                  $r = $this->db->select("`id` IN ('$ids')"'*''''''''id');  
  35.                  if (!emptyempty($r)) {  
  36.                      foreach ($r as $k=>$v) {  
  37.                          if (isset($return[$k])) $return[$k] = array_merge($v$return[$k]);  
  38.                      }  
  39.                  }  
  40.              }  
  41.          }  
  42.          return $return;  
  43.      }  
  44. //修改为: 
  45.      public function lists($data) {  
  46.          $catid = intval($data['catid']);  
  47.            
  48.          if(isset($data['where'])) {  
  49.              $sql = $data['where'];  
  50.          } else {  
  51.              $thumb = intval($data['thumb']) ? " AND thumb != ''" : '';  
  52.              if(!emptyempty($catid)) {  
  53.                  if(!$this->set_modelid($catid)) return false;  
  54.                  if($this->category[$catid]['child']) {  
  55.                      $catids_str = $this->category[$catid]['arrchildid'];  
  56.                      $pos = strpos($catids_str,',')+1;  
  57.                      $catids_str = substr($catids_str$pos);  
  58.                      $sql = "status=99 AND catid IN ($catids_str)".$thumb;  
  59.                  } else {  
  60.                      $sql = "status=99 AND catid='$catid'".$thumb;  
  61.                  }  
  62.              }  
  63.              else {  
  64.                  $sql = "status=99".$thumb;  
  65.              }  //phpfensi.com 
  66.                    
  67.          }  
  68.          $order = $data['order'];  
  69.    
  70.          $return = $this->db->select($sql'*'$data['limit'], $order'''id');  
  71.                            
  72.          //调用副表的数据  
  73.          if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {  
  74.              $ids = array();  
  75.              foreach ($return as $v) {  
  76.                  if (isset($v['id']) && !emptyempty($v['id'])) {  
  77.                      $ids[] = $v['id'];  
  78.                  } else {  
  79.                      continue;  
  80.                  }  
  81.              }  
  82.              if (!emptyempty($ids)) {  
  83.                  $this->db->table_name = $this->db->table_name.'_data';  
  84.                  $ids = implode('\',\''$ids);  
  85.                  $r = $this->db->select("`id` IN ('$ids')"'*''''''''id');  
  86.                  if (!emptyempty($r)) {  
  87.                      foreach ($r as $k=>$v) {  
  88.                          if (isset($return[$k])) $return[$k] = array_merge($v$return[$k]);  
  89.                      }  
  90.                  }  
  91.              }  
  92.          }  
  93.          return $return;  
  94.      }  

修改代码后,即能调取全站最新文章.

调用方法:{pc:content action="lists" num="10" order="id DESC" cache="3600"}

Tags: Phpcms最新文章 Phpcms全站最新

分享到: