• 環(huán)境要求
PHP必須開啟了curl擴展
百度快速收錄可以縮短百度爬蟲發(fā)現(xiàn)您站點新鏈接的時間,使新發(fā)布的頁面可以在第一時間被百度收錄
織夢程序我們可以在后臺添加文檔完成那一刻即時主動推送到百度快速收錄,也可以在后臺文檔列表里批量推送
效果
  • 織夢百度快速收錄推送教程
變量名稱
cfg_shoulu_push
參數(shù)說明
百度快速收錄
變量值
登錄你的百度平臺 https://ziyuan.baidu.com 獲取接口調(diào)用地址
如圖,注意你的站點域名要對應(yīng)上
2、打開 /dede(后臺目錄)/inc/inc_archives_functions.php 在文件最末尾插入
/**
 * 百度主動推送
 */
function shoulu_push($id="",$qstr="")
{
global $cfg_multi_site,$cfg_basehost,$cfg_shoulu_push;
if(!empty($id) && !empty($cfg_shoulu_push))
{
if( !empty($id) && empty($qstr) ) $qstr = $id;
if($qstr=='')
{
exit();
}
$qstrs = explode('`',$qstr);
$cfg_domain = $cfg_multi_site == 'N' ? $cfg_basehost : '';
$urls = array();
$i = 0;
foreach($qstrs as $aid)
{
$i++;
$arcrow = GetOneArchive($aid);
$url = $cfg_domain.$arcrow['arcurl'];
$urls[] = $url;
$artlist .= $url."<br />";
}
if($i>1) $artlist = "";
if(!empty($urls)){
$ch = curl_init();
$options =  array(
CURLOPT_URL => trim($cfg_shoulu_push),
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);
curl_close($ch);
$result = json_decode($result, true);
if(isset($result['success'])){
$not_same_site = isset($result['not_same_site'][0]) ? " <font style='color:#f00;'>推送鏈接與百度綁定站點不一致</font> " : "";
$not_valid = isset($result['not_valid'][0]) ? " <font style='color:#f00;'>推送鏈接不合法</font> " : "";
return $not_same_site . $not_valid . '百度快速收錄推送成功 '.$result['success'].' 條!當天剩余 '.$result['remain'].' 條可推送!'.$artlist;
}else{
return '百度快速收錄推送失敗,錯誤碼:'.$result['error'].'<a href=https://ziyuan.baidu.com/college/courseinfo?id=267&page=2#h2_article_title12 target=_blank>詳情</a>';
}
}
return "沒有數(shù)據(jù)被推送!";
}
}
3、找到后臺文檔發(fā)布程序PHP文件
【普通文章】模型的是
/dede/article_add.php
【圖片集】模型的是
/dede/album_add.php
【軟件】模型的是
/dede/soft_add.php
【商品/自定義模型】模型的是
/dede/archives_add.php
根據(jù)你的需要在對應(yīng)的php文件中找到
//返回成功信息
在它上面加入
if(!empty($cfg_baidu_push))
{
$backurl .= "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shoulu_push($arcID)."</p>";
}
繼續(xù)找到
line-height:36px;height:36px
改成
line-height:36px;
至此,織夢發(fā)布文檔主動推送到百度功能完成。
織夢后臺文檔列表添加批量推送至百度快速收錄
效果如圖
  • 批量推送實現(xiàn)教程
1、打開 /dede/templets/content_list.htm (軟件模型和自定義模型是 /dede/templets/content_i_list.htm) 找到
刪除屬性
這一行,在它下面添加
<a href="javascript:shoulu_push(0)" class="coolbg">&nbsp;推送至百度&nbsp;</a>
<script type="text/javascript">
function baidu_push(aid)
{
var qstr=getCheckboxItem();
if(aid==0) aid = getOneItem();
location="archives_do.php?aid="+aid+"&dopost=shoulu_push&qstr="+qstr;
}
</script>
2、打開 /dede/archives_do.php 找到末尾一行的
?>
在它上面加入
else if($dopost=='shoulu_push')
{
    if( !empty($aid) && empty($qstr) ) $qstr = $aid;
    
    if($qstr=='')
    {
        ShowMsg('參數(shù)無效!',$ENV_GOBACK_URL);
        exit();
    }
    require_once(DEDEADMIN.'/inc/inc_archives_functions.php');
    $result = shoulu_push($qstr);
    ShowMsg($result,$ENV_GOBACK_URL,0,5000);
    exit();
}