1. 程式人生 > 其它 >phpcms呼叫全站最新文章列表的方法

phpcms呼叫全站最新文章列表的方法

Phpcms呼叫全站最新文章需要修改檔案:\phpcms\modules\content\classes\content_tag.class.php,找到以下函式:

/**
      * 列表頁標籤
      * @param $data
      */
     public function lists($data) { 
         $catid = intval($data['catid']); 
         if(!$this->set_modelid($catid)) return false; 
         if(isset($data['where'])) { 
             
$sql = $data['where']; } else { $thumb = intval($data['thumb']) ? " AND thumb != ''" : ''; if($this->category[$catid]['child']) { $catids_str = $this->category[$catid]['arrchildid']; $pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos); $sql = "status=99 AND catid IN ($catids_str)".$thumb; } else { $sql = "status=99 AND catid='$catid'".$thumb; } } $order = $data['order']; $return = $this->db->select($sql
, '*', $data['limit'], $order, '', 'id'); //呼叫副表的資料 if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) { $ids = array(); foreach ($return as $v) { if (isset($v['id']) && !emptyempty($v['id'])) { $ids[] = $v['id']; } else { continue; } } if (!emptyempty($ids)) { $this->db->table_name = $this->db->table_name.'_data'; $ids = implode('\',\'', $ids); $r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id'); if (!emptyempty($r)) { foreach ($r as $k=>$v) { if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]); } } } } return $return
; }

修改為:

/**
      * 列表頁標籤
      * @param $data
      */
     public function lists($data) { 
         $catid = intval($data['catid']); 
          
         if(isset($data['where'])) { 
             $sql = $data['where']; 
         } else { 
             $thumb = intval($data['thumb']) ? " AND thumb != ''" : ''; 
             if(!emptyempty($catid)) { 
                 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 = "status=99 AND catid IN ($catids_str)".$thumb; 
                 } else { 
                     $sql = "status=99 AND catid='$catid'".$thumb; 
                 } 
             } 
             else { 
                 $sql = "status=99".$thumb; 
             } 
                  
         } 
         $order = $data['order']; 
  
         $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id'); 
                          
         //呼叫副表的資料
         if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) { 
             $ids = array(); 
             foreach ($return as $v) { 
                 if (isset($v['id']) && !emptyempty($v['id'])) { 
                     $ids[] = $v['id']; 
                 } else { 
                     continue; 
                 } 
             } 
             if (!emptyempty($ids)) { 
                 $this->db->table_name = $this->db->table_name.'_data'; 
                 $ids = implode('\',\'', $ids); 
                 $r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id'); 
                 if (!emptyempty($r)) { 
                     foreach ($r as $k=>$v) { 
                         if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]); 
                     } 
                 } 
             } 
         } 
         return $return; 
     } 

修改程式碼後,即能調取全站最新文章。
呼叫方法:

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