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教程