我們的網(wǎng)站使用的是PHPCMSV9系統(tǒng)開發(fā)的,網(wǎng)站越來越大,新聞頁右側(cè)推薦內(nèi)容經(jīng)常更新不及時,影響網(wǎng)站的流量。所以在服務(wù)器上開啟了ssi功能,也就是常說的文件包含功能。這樣就可以在所有的頁面上添加一個公用的靜態(tài)頁面,每次更新右側(cè)內(nèi)容時只需要更新這一塊的靜態(tài)就可以了,相比之前更新全站才能全右側(cè)信息顯示最新新聞,這樣的效率能夠提高千萬倍。至于怎么給PHPCMSV9添加ssi功能我會另寫文章記錄全過程。
既然只需要更新指定的靜態(tài)就可以更新全站,所以定時更新這些靜態(tài)頁能省很多編輯的時間。特此我寫了個更新指定欄目下文字的程序與大家分享。
<?php
/*
* http://www.bcty365.com/index.php?m=content&c=autohtml&a=show&catid=6&start=0&offset=10&pwd=house
* catid 需要更新的欄目ID號,不能有子欄目(必填)
* start 從第幾條開始(選填)
* offset 更新多少條(選填)
* pwd 安全密碼
*/
defined('IN_PHPCMS') or exit('No permission resources.');
//模型緩存路徑
define('CACHE_MODEL_PATH', CACHE_PATH . 'caches_model' . DIRECTORY_SEPARATOR . 'caches_data' . DIRECTORY_SEPARATOR);
pc_base::load_app_func('util', 'content');
class autohtml {
private $db, $categorys;
function __construct() {
$this->db = pc_base::load_model('content_model');
$this->siteid = get_siteid();
$this->categorys = getcache('category_content_' . $this->siteid, 'commons');
foreach ($_GET as $k => $v) {
$_POST[$k] = $v;
}
}
//首頁
public function init() {
}
/**
* 生成內(nèi)容頁
*/
public function show() {
$catid = safe_replace($_GET['catid']);
$start = safe_replace($_GET['start']);
$offset = safe_replace($_GET['offset']);
$pwd = safe_replace($_GET['pwd']);
if ($pwd != house) {
echo '安全驗(yàn)證未通過';
exit;
}
if (!$catid) {
echo "catid未設(shè)置,請設(shè)置get參數(shù) set_catid";
exit;
}
if (!$start)
$start = 0;
if (!$offset)
$offset = 10;
$this->html = pc_base::load_app_class('html');
$modelid = $this->categorys[$catid]['modelid'];
if (!$modelid) {
echo 'modelid設(shè)置錯誤,請查看set_catid是否正確';
exit;
}
//設(shè)置模型數(shù)據(jù)表名www.bcty365.com
$this->db->set_model($modelid);
$table_name = $this->db->table_name;
$where = " WHERE status=99 AND catid='$catid'";
$order = 'ASC';
$rs = $this->db->query("SELECT * FROM `$table_name` $where ORDER BY `id` $order LIMIT $start,$offset");
$data = $this->db->fetch_array($rs);
if (!$data) {
echo "暫無數(shù)據(jù)";
exit;
}
$tablename = $this->db->table_name . '_data';
$this->url = pc_base::load_app_class('url');
foreach ($data as $r) {
if ($r['islink'])
continue;
//寫入文件
$this->db->table_name = $tablename;
$r2 = $this->db->get_one(array('id' => $r['id']));
if ($r2)
$r = array_merge($r, $r2);
if ($r['upgrade']) {
$urls[1] = $r['url'];
} else {
$urls = $this->url->show($r['id'], '', $r['catid'], $r['inputtime']);
}
$this->html->show($urls[1], $r, 0, 'edit', $r['upgrade']);
}
echo "成功";
}
}
?>
把以上內(nèi)容復(fù)制一份添加到自己的PHPCMSV9系統(tǒng)下的/phpcms/modules/content目錄下,就可以用http://www.bcty365.com/index.php?m=content&c=autohtml&a=show&catid=6&start=0&offset=10&pwd=house這樣的方式訪問,參數(shù)請參照說明。這樣就可以把這個鏈接添加到服務(wù)器或是監(jiān)控寶那樣定時訪問指定頁面的定時功能上,這樣就可以實(shí)現(xiàn)指定欄目下的所有文章定時更新。
新聞熱點(diǎn)
疑難解答
圖片精選