織夢DedeCMS網站一鍵推送功能有利于搜索引擎蜘蛛在第一時間抓取到網站的最新內容,加快收錄速度。
第一步:百度站長、MIP、移動推送
在織夢后臺目錄(默認為dede),新建一個baidu.php文件,放入以下代碼。
<?php require_once ("../include/common.inc.php"); require_once "../include/arc.partview.class.php"; require_once('../include/charset.func.php'); $limit = 2000; //百度一次性推送最多2000條記錄,所以限制推送數量為2000 $query = "SELECT arch.id,types.typedir FROM dede_arctype as types inner join dede_archives as arch on types.id=arch.typeid ORDER BY pubdate DESC LIMIT $limit"; //這里dede換成你們自己的表前綴 $urls=""; $dsql->Execute('arch.id,types.typedir',$query); while($row = $dsql->GetArray('arch.id,types.typedir')) { $urls.="http://www.demo.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; // http://www.demo.com 換成你們自己的域名 } $urls=substr($urls,0,-1); $urls = explode(",",$urls); $api = 'http://data.zz.baidu.com/urls?site=www.demo.com&token=********'; // 前邊的api換成自己的推送 API $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); echo $result.count($urls); ?>
注意:上面有三個注釋的地方,要改成自己的。
其他MIP推送、移動推送同理,多新建幾個PHP,更換下域名和API推送接口即可。
第二步:熊掌號推送
熊掌號只能推送當天更新的數據,所以要代碼跟上面的有點不一樣,要加個時間限制。
在織夢后臺目錄(默認為dede),新建一個xz.php文件,放入以下代碼。
<?php require_once ("../include/common.inc.php"); require_once "../include/arc.partview.class.php"; require_once('../include/charset.func.php'); $year = date("Y"); $month = date("m"); $day = date("d"); $dayBegin = mktime(0,0,0,$month,$day,$year);//當天開始時間戳 $dayEnd = mktime(23,59,59,$month,$day,$year);//當天結束時間戳 $query = "SELECT arch.id,types.typedir FROM dede_arctype as types inner join dede_archives as arch on types.id=arch.typeid where pubdate<".$dayEnd." AND pubdate>".$dayBegin.""; //這里dede換成你們自己的表前綴 $urls=""; $dsql->Execute('arch.id,types.typedir',$query); while($row = $dsql->GetArray('arch.id,types.typedir')) { $urls.="http://www.demo.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; // http://www.demo.com 換成你們自己的域名 } $urls=substr($urls,0,-1); $urls = explode(",",$urls); $api = 'http://data.zz.baidu.com/urls?appid=****&token=***&type=realtime'; // 前邊的api換成自己的推送 API $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); echo $result.count($urls); ?>
第三步:在織夢后臺添加推送菜單
打開/dede/inc/inc_menu.php,大概136行下面添加剛剛新建的PHP文件
<m:item name='一鍵推送PC' link='baidu.php' rank='sys_MakeHtml' target='main' /> <m:item name='一鍵推送PC' link='xz.php' rank='sys_MakeHtml' target='main' />
測試
顯示success,則說明功能正常。