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

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

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

  1. /** 
  2.       * 列表页标签 
  3.       * @param $data 
  4.       */ 
  5.      public function lists($data) { 
  6.          $catid = intval($data['catid']); 
  7.          if(!$this->set_modelid($catid)) return false; 
  8.          if(isset($data['where'])) { 
  9.              $sql = $data['where']; 
  10.          } else { 
  11.              $thumb = intval($data['thumb']) ? " AND thumb != ''" : ''
  12.              if($this->category[$catid]['child']) { 
  13.                  $catids_str = $this->category[$catid]['arrchildid']; 
  14.                  $pos = strpos($catids_str,',')+1; 
  15.                  $catids_str = substr($catids_str$pos); 
  16.                  $sql = "status=99 AND catid IN ($catids_str)".$thumb
  17.              } else { 
  18.                  $sql = "status=99 AND catid='$catid'".$thumb
  19.              } 
  20.          } 
  21.          $order = $data['order']; 
  22.   
  23.          $return = $this->db->select($sql'*'$data['limit'], $order'''id'); 
  24.                           
  25.          //调用副表的数据 
  26.          if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) { 
  27.              $ids = array(); 
  28.              foreach ($return as $v) { 
  29.                  if (isset($v['id']) && !emptyempty($v['id'])) { 
  30.                      $ids[] = $v['id']; 
  31.                  } else { 
  32.                      continue
  33.                  } 
  34.              } 
  35.              if (!emptyempty($ids)) { 
  36.                  $this->db->table_name = $this->db->table_name.'_data'
  37.                  $ids = implode('\',\''$ids); 
  38.                  $r = $this->db->select("`id` IN ('$ids')"'*''''''''id'); 
  39.                  if (!emptyempty($r)) { 
  40.                      foreach ($r as $k=>$v) { 
  41.                          if (isset($return[$k])) $return[$k] = array_merge($v$return[$k]); 
  42.                      } 
  43.                  } 
  44.              } 
  45.          } 
  46.          return $return
  47.      } 
修改为:
  1. /** 
  2.       * 列表页标签 
  3.       * @param $data 
  4.       */ 
  5.      public function lists($data) { 
  6.          $catid = intval($data['catid']); 
  7.           
  8.          if(isset($data['where'])) { 
  9.              $sql = $data['where']; 
  10.          } else { 
  11.              $thumb = intval($data['thumb']) ? " AND thumb != ''" : ''
  12.              if(!emptyempty($catid)) { 
  13.                  if(!$this->set_modelid($catid)) return false; 
  14.                  if($this->category[$catid]['child']) { 
  15.                      $catids_str = $this->category[$catid]['arrchildid']; 
  16.                      $pos = strpos($catids_str,',')+1; 
  17.                      $catids_str = substr($catids_str$pos); 
  18.                      $sql = "status=99 AND catid IN ($catids_str)".$thumb
  19.                  } else { 
  20.                      $sql = "status=99 AND catid='$catid'".$thumb
  21.                  } 
  22.              } 
  23.              else { 
  24.                  $sql = "status=99".$thumb
  25.              } 
  26.                   
  27.          } 
  28.          $order = $data['order']; 
  29.   
  30.          $return = $this->db->select($sql'*'$data['limit'], $order'''id'); 
  31.                           
  32.          //调用副表的数据 
  33.          if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) { 
  34.              $ids = array(); 
  35.              foreach ($return as $v) { 
  36.                  if (isset($v['id']) && !emptyempty($v['id'])) { 
  37.                      $ids[] = $v['id']; 
  38.                  } else { 
  39.                      continue
  40.                  } 
  41.              } 
  42.              if (!emptyempty($ids)) { 
  43.                  $this->db->table_name = $this->db->table_name.'_data'
  44.                  $ids = implode('\',\''$ids); 
  45.                  $r = $this->db->select("`id` IN ('$ids')"'*''''''''id'); 
  46.                  if (!emptyempty($r)) { 
  47.                      foreach ($r as $k=>$v) { 
  48.                          if (isset($return[$k])) $return[$k] = array_merge($v$return[$k]); 
  49.                      } 
  50.                  } 
  51.              } 
  52.          } 
  53.          return $return
  54.      } 
修改代码后,即能调取全站最新文章。
调用方法:{pc:content action="lists" num="10" order="id DESC" cache="3600"}

查看更多 phpcms教程  phpcms模板

来源:http://www.cnblogs.com/esion//所属分类:PHPCms教程/更新时间:2012-08-05
相关PHPCms教程