效果:
注意:@id
里面的地址必須是自適應網(wǎng)站或者手機站,pc端鏈接是不支持!
百度官方JSON-LD示例:
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "https://ziyuan.baidu.com/college/articleinfo?id=1464",
"appid": "1582926961485115",
"title": "百度移動搜索落地頁體驗白皮書——廣告篇2.0",
"images": [
"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png",
"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_ca79a146.png",
"https://m.baidu.com/static/index/plus/plus_logo.png"
],
"description": "優(yōu)質(zhì)合理的廣告作為信息的補充,廣受用戶喜歡。2017年初百度用戶體驗部針對用戶進行了滿意度調(diào)研,發(fā)現(xiàn)很多惡意低質(zhì)的廣告嚴重破壞著用戶的搜索體驗。",
"pubDate": "2017-06-15T08:00:01"
}
</script>
織夢DEDECMS熊掌號JSON LD結(jié)構(gòu)化數(shù)據(jù)代碼分享
文章內(nèi)容頁調(diào)用代碼:
<script type="application/ld+json"> {
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "{dede:global.cfg_basehost/}{dede:geturl runphp='yes'}
@me = GetCurUrl();
{/dede:geturl}",
"appid": "你的熊掌號ID",
"title": "{dede:field.title/}",
"images": [
"{dede:global.cfg_basehost/}{dede:field.litpic/}"
],
"description":"{dede:field.description function=html2text(@me)/}",
"pubDate":"{dede:field.pubdate function="MyDate('Y-m-d\TH:i:s',@me)"/}",
"Update":"{dede:field.pubdate function="MyDate('Y-m-d\TH:i:s',@me)"/}"
}
</script>
首頁調(diào)用代碼:
<script type="application/ld+json"> {
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "{dede:global.cfg_basehost/}",
"appid": "你的熊掌號ID",
"title": "{dede:global.cfg_webname/}",
"images": [
"https://www.xycn.org/style/images/logo.png"
],
"description":"{dede:global.cfg_description/}",
"pubDate": "{dede:tagname runphp='yes'}@me = date("Y-m-d\TH:i:s", time());{/dede:tagname}"
}
</script>
]]>
先看效果,如果你需要百度主動推送,請點擊織夢dedecms5.7百度主動推送(實時)
打開你的熊掌號管理后臺。記住你的熊掌號接口調(diào)用地址
第一步,打開你的網(wǎng)站后臺-系統(tǒng)-基本參數(shù),添加新變量,如下圖,在你的變量值里面添加熊掌號接口調(diào)用地址
變量名稱:cfg_xiong_push
變量值:(填寫您的熊掌號接口調(diào)用地址)
變量類型:文本
參數(shù)說明:熊掌號推送接口
第二步,打開 /dede/inc/inc_archives_functions.php 在文件最后插入下面代碼:
/**
* 熊掌主動推送
*/
function xiong_push($id="",$qstr="")
{
global $cfg_multi_site,$cfg_basehost,$cfg_xiong_push;
if(!empty($id) && !empty($cfg_xiong_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_xiong_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['error'])){
return '熊掌主動推送失敗,錯誤碼:'.$result['error'].' message:'.$result['message'];
}else{
$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_batch'].' 條!當天剩余 '.$result['remain_batch'].' 條可推送!'.$artlist;
}
}
return "沒有數(shù)據(jù)被推送!";
}
}
打開/dede/article_add.php,搜索
//返回成功信息
在它上面添加
if(!empty($cfg_xiong_push))
{
$backurl .= "<p> ".xiong_push($arcID)."</p>";
}
繼續(xù)搜索
line-height:36px;height:36px
替換成
line-height:36px;
如果在這之前你添加過百度主動推送,刪除樣式這一步可忽略。
]]>