DIscuz 改造熊掌號的難度主要來自 json_LD的處理上,接下來進行稍微的修改(影響后續升級)進行熊掌號的改造:
改造需要具備1個條件,就是手機站綁定了二級域名,如果沒綁定二級域名的,請把教程里的
[url=http://$_G[setting][domain][app][mobile]http://$_G[setting][domain][app][mobile[/url]]
復制代碼
和
[url=http://$_G[setting][domain][app][default]http://$_G[setting][domain][app][default[/url]]
復制代碼
換成你自己的論壇域名
第一步打開:
/source/module/portal/portal_view.php
在75行左右的:
$content['content'] = blog_bbcode($content['content']);
復制代碼
下面添加:
if(!preg_match_all("/(src)=([/"|']?)([^ /"'>]+)//2/is", $content['content'], $showimg));//官方號改造之內圖數組化
foreach($showimg as $images) {
$showimg = $images;
}
復制代碼
第二步:
在243行左右的:
$article['timestamp'] = $article['dateline'];
復制代碼
上面增加:
$article['gtime'] = date("Y-m-d/TH:i:s",$article['dateline']);//官方號改造之時間加T
復制代碼
然后就完成了JSON_LD 里主要數據的改造
[size=18.6667px]接下來就是改造模板了:
然后在 DIscuz 門戶的手機端模板的 header 文件里寫入:
添加canonical標簽(必選):
<link rel="canonical" href=" http://$_G[setting][domain][app][mobile]/{$viewurl}"/>
復制代碼
添加Json_LD數據(必選):
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "http://$_G[setting][domain][app][mobile]/{$viewurl}",
"appid": "1539897736717695",
"title": "{$article[title]}",
"images": [
"{if ($showimg[0])}http://$_G[setting][domain][app][default]/{$showimg[0]}{/if}"{if ($showimg[2])},"http://$_G[setting][domain][app][default]/{$showimg[1]}","http://$_G[setting][domain][app][default]/{$showimg[2]}"{/if}"
],
"description": "{$article[summary]}",
"pubDate": "{$article[gtime]}"
}
</script>
復制代碼
添加官方號ID聲明(H5頁面必選):
<script src="//msite.baidu.com/sdk/c.js?appid=你的 appid"></script>
然后在門戶內容頁 view.htm 里最下面的
<!--{template common/footer}-->
最后就是添加我們的 添加關注功能代碼 代碼放在文章內容即可,這里也是強烈推薦大家去添加的,添加之后用戶看到文章之后可以通過關注代碼關注我們的熊掌號,同時我們就可以通過運營中心將我們的內容推送給用戶!并且可以更快的和用戶去溝通!