phpcms 調取全站文章

來源:互聯網
上載者:User

標籤:style   blog   color   使用   檔案   資料   io   for   

路徑:phpcms/module/content/classes/content_tag.class.php 添加如下方法

  /** * 列表頁標籤:主要返回的是主表中資料與附表中資料 * @param $data */ public function lists_all($data) { $this->db->set_model(1);//將模型手動指定為文章模型,為什嗎?因為根據原始碼的套路,模型id的是根據catid來設定的,但是現在擷取的是所有的文章,而不局限於某個欄目,所以只能手動將其設定為文章模型1 //根據模型id擷取當前模型所對應的模型表和資料表 1:文檔模型-news 3:圖片模型-picture 2:下載模型-download if(isset($data[‘where‘])) { //如果pc標籤中設定了where屬性,一般情況下不存在 $sql = $data[‘where‘]; } else { //如果pc標籤中沒有設定where屬性 $thumb = intval($data[‘thumb‘]) ? " AND thumb != ‘‘" : ‘‘; //如果有thumb屬性 $sql = "status=99 ".$thumb;//去掉catid條件 //如果當前欄目下不存在子欄目 } $order = $data[‘order‘]; //pc標籤中order屬性 //$sql作為一個條件出現,調用的是model.calss.php檔案中的select方法,返回結果集數組,並按照鍵名‘id‘排序 $return = $this->db->select($sql, ‘*‘, $data[‘limit‘], $order, ‘‘, ‘id‘);//從資料庫中擷取主表資料,使用的也是sql語句查詢 //如果需要在前台顯示類別名稱,可添加如下代碼 $TYPES = getcache(‘type_content‘,‘commons‘);//擷取類別快取檔案,此檔案快取了所有與類別資訊相關的資訊 foreach ($return as $key=>$v) { $return[$key][typename]=$TYPES[$v[‘typeid‘]][name];//給$return中的每篇文章追加一個類別欄位 } //echo "<pre>"; //print_r($return); //調用副表的資料 if (isset($data[‘moreinfo‘]) && intval($data[‘moreinfo‘]) == 1) { //如果pc標籤中設定了moreinfo屬性:是否調用附表資料 $ids = array(); //$return為返回的主表資料 foreach ($return as $v) { //迴圈主表中的記錄資訊:$v-主表中的每條記錄 if (isset($v[‘id‘]) && !empty($v[‘id‘])) { $ids[] = $v[‘id‘]; //ids[]是主表中排序完成的文章id數組 } else { continue; } } if (!empty($ids)) { $this->db->table_name = $this->db->table_name.‘_data‘; //副表名 $ids = implode(‘\‘,\‘‘, $ids); //以逗號拼接成一個字串 $r = $this->db->select("`id` IN (‘$ids‘)", ‘*‘, ‘‘, ‘‘, ‘‘, ‘id‘);//查詢與主表中資料有關的副表中的資料 if (!empty($r)) { foreach ($r as $k=>$v) { //副表中的資料 //$return:返回的主表中的資料,主表中的id欄位值與附表中的id欄位值是對應的,也就是說一篇文章在主表中儲存的id跟在附表中儲存的id的值是相等的 if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);//主表中資料與副表中資料合併 } } } } return $return; }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.