在這里,CMSYOU與大家分享怎么讓Phpcms V9自動發布文章,所謂Phpcms V9文章定時發布。
在Wordpress中,添加博文的時候,發布日期寫未來的時間,那么在時間到來的時候,文章會自動發布出現在首頁,做到預約發布、自動發布。其實在Phpcms V9中同樣可以做到定時發布,這樣就可以預先設置些文章,在假期可以定時發布,避免出現類似CMSYOU在過年期間,更新文章停了1個月的時間。
具體怎么做到Phpcms V9文章定時發布呢?這一方法來自PC論壇,具體方法如下。
1、修改api/count.php這一文件,在PHP語句結束代碼 ?>前,加入以下代碼:
代碼如下:
$urlobj = pc_base::load_app_class('url', 'content');
$html = pc_base::load_app_class('html', 'content');
$modelid = $modelid ? $modelid : intval($_GET['modelid']);
$content_db = $content_db ? $content_db : pc_base::load_model('content_model');
$content_db->set_model($modelid);
$where = ' status = 1 and inputtime <= '.SYS_TIME;
$r = $content_db->count($where);
if( !empty($r) ){ //執行update操作
$ids = $content_db->select($where, 'id,catid', $r, '', '', 'id');
foreach($ids AS $kid=>$v){
$catid = $v['catid'];
$id = $kid;
$r = $content_db->get_content($catid,$id);
$urls = $urlobj->show($id, 0, $catid, $r['inputtime'], $r['prefix'],$r,'add');
if($urls['content_ishtml']) $html->show($urls[1],$urls['data'],0);
$html->index();
$html->create_relation_html($catid);
}
$content_db->update( array('status'=>99),$where );
}
這樣,我們借統計代碼在更新的時候,讓需要審核的文章在預定的時間點通過發布。
2、在文章頁面的模板里邊添加統計代碼:
代碼如下:
默認的模板里邊已經默認添加了這句統計代碼,檢查下,這樣文章在被瀏覽的時候,觸發這個JS,就會執行第一步添加的通過審核代碼。
具體上面的兩個步驟,大家可以嘗試下!同時歡迎朋友多研究、多嘗試。