站长图库向大家介绍了织梦DedeCMS,一键推送,百度站长,熊掌号功能等相关知识,希望对您有所帮助
织梦DedeCMS网站一键推送功能有利于搜索引擎蜘蛛在第一时间抓取到网站的最新内容,加快收录速度。
第一步:百度站长、MIP、移动推送
在织梦后台目录(默认为dede),新建一个baidu.php文件,放入以下代码。
<?phprequire_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文件,放入以下代码。
<?phprequire_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,则说明功能正常。