溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

使用織夢(mèng)sitemap地圖怎么實(shí)現(xiàn)實(shí)時(shí)推送

發(fā)布時(shí)間:2020-12-18 14:48:42 來(lái)源:億速云 閱讀:122 作者:Leah 欄目:開發(fā)技術(shù)

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)使用織夢(mèng)sitemap地圖怎么實(shí)現(xiàn)實(shí)時(shí)推送,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

1.手動(dòng)創(chuàng)建一個(gè)文件,每天訪問這個(gè)文件就可以把當(dāng)天的全部文章推送到百度搜索引擎. 在根目錄下面創(chuàng)建一個(gè)tuisong.php  訪問后會(huì)返回百度接口結(jié)果

<?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);//當(dāng)天開始時(shí)間戳
$dayEnd = mktime(23,59,59,$month,$day,$year);//當(dāng)天結(jié)束時(shí)間戳
$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.baidu.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; 
 //將上邊的http://baidub.com換成你的網(wǎng)址
}
$urls=substr($urls,0,-1);
$urls = explode(",",$urls);
$api = 'http://data.zz.baidu.com/urls?site=www.baidu.com&token=hereistoken'; // 前邊的site換成自己的site xxx換成自己的密鑰
$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);
?>

查看推送反饋

推送成功

狀態(tài)碼為200,可能返回以下字段:
字段 是否必選 參數(shù)類型 說(shuō)明
success 是 int 成功推送的url條數(shù)
remain 是 int 當(dāng)天剩余的可推送url條數(shù)
not_same_site 否 array 由于不是本站url而未處理的url列表
not_valid 否 array 不合法的url列表
成功返回示例:

復(fù)制代碼 代碼如下:


{
    "remain":4999998,
    "success":2,
    "not_same_site":[],
    "not_valid":[]
}

推送失敗

狀態(tài)碼為4xx,返回字段有:
字段 是否必傳 類型 說(shuō)明
error 是 int 錯(cuò)誤碼,與狀態(tài)碼相同
message 是 string 錯(cuò)誤描述
失敗返回示例:

復(fù)制代碼 代碼如下:


{
    "error":401,
    "message":"token is not valid"
}

2、第二種是發(fā)布一篇文章,就像百度推送一次,這種比較方便,我就是用這種

打開織夢(mèng)后臺(tái)的 article_add.php 文件.找到差不多262行的樣子

 注意:
如果你系統(tǒng)設(shè)置的-》核心選項(xiàng)

使用織夢(mèng)sitemap地圖怎么實(shí)現(xiàn)實(shí)時(shí)推送 

如果是否直接. 加入以下代碼,否則 注意下面的提示

使用織夢(mèng)sitemap地圖怎么實(shí)現(xiàn)實(shí)時(shí)推送 

//百度推送
$urls="http://www.baidu.com".$artUrl;//前面域名換成你自己的 如果上面圖片選擇的是是 就把"http://baidu.com". 去掉
$urls = explode(",",$urls);
$api = 'http://data.zz.baidu.com/urls?site=www.0cx.cc&token=hereistoken'; // 前邊site換成自己的site xxx換成自己的密鑰
$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);

就OK了  ,如果想看添加成功沒,可以在修改下面一兩行的樣子的代碼

復(fù)制代碼 代碼如下:


請(qǐng)選擇你的后續(xù)操作".$result.$urls[0].":


result是看百度返回的結(jié)果,urls是看你推送的url.

基本上就OK了,如果你想讓修改文章的時(shí)候也事實(shí)推送,就類似我上面一樣去修改article_edit.php就好了.

上述就是小編為大家分享的使用織夢(mèng)sitemap地圖怎么實(shí)現(xiàn)實(shí)時(shí)推送了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI