首先我们需要修改当前主题的 header.php
和 footer.php
文件,在里面分别添加代码,以实现熊掌号的页面改造,具体如下:
header.php文件的修改
由于 Typecho 默认是没 Canonical 标签的,所以我们要在 Header 中加入 Canonical 标签。
以handsome主题为例,修改:/usr/themes/handsome/component/header.php
文件加入:
<link rel="canonical" href="<?php $this->permalink() ?>"/>
footer.php文件的修改
以handsome主题为例,修改:/usr/themes/handsome/component/footer.php
文件。
在<?php $this->footer(); ?>后加入:
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "<?php $this->permalink() ?>",
"appid": "你的 APPID",
"title": "<?php $this->title() ?>",
"images": ["<?php $this->fields->XZHimages(); ?>"],
"description": "<?php $this->description() ?>",
"pubDate": "<?php $this->date('Y-m-d\TH:i:s'); ?>"
}
</script>
<script src="//msite.baidu.com/sdk/c.js?appid=你的 APPID"></script>
只要将 你的 APPID 修改为你的 APPID 就 ok 了!
值得注意的是,由于 Typecho 貌似没有缩略图、特色图片输出这样的机制,所以图片功能,就需要自己实现了,我这里用的是 自定义字段 的姿势实现的。
设置 自定义字段,内容为 XZHimages 字符 缩略图 url 地址,如下图所示:
使用 BaiduSubmit for Typecho 版插件实现自动推送到百度熊掌号。
自动推送有现成的插件:BaiduSubmit,虽然最后一次更新已经是 15 年了,但是由于熊掌号的 API 推送是兼容站长平台的链接提交的,所以插件也是支持的。
首先在百度熊掌号的“API提交”里的“新增内容接口”里获取“推送接口”链接,如下图:
然后在Typecho的BaiduSubmit插件设置里的“接口调用地址”里使用上面的百度熊掌号“推送接口”链接,如下图:
本文标签:handsome, 熊掌号
本文链接: https://www.gengjian.net/2019/06/24/128.html