近2年的熊掌号崛起的很快,百度也在前面的推广熊掌号,在百度的每个页面几乎都可以看见熊掌号的推广。一些意识到熊掌号趋势的站长都纷纷开通了属于自己的熊掌号,也有些站长开通了熊掌号但是不会用,因为需要在网站的页面上添加熊掌号代码。添加代码的作用是可以把你的粉丝留住,可以与熊掌号的粉丝互动,给粉丝推送信息。
现在流行的网站程序有很多种,WordPress简称WP是针对个人门户最受欢迎的的一个,程序简单。今天给大家带来的就是WordPress程序熊掌号页面改造,步骤很简单,涉及的文件就三个:functions.php,head.php,single.php
第一步:在头部文件(head.php)添加JS、JSON_LD代码
<script src=”//msite.baidu.com/sdk/c.js?appid=此处填写熊掌号ID”></script>
然后还需要在头部区域添加JSON_LD数据
<!–熊掌号开始–>
<script src=”//msite.baidu.com/sdk/c.js?appid=1595281659287879″></script>
<script type=”application/ld+json”>
{
“@context”: “https://ziyuan.baidu.com/contexts/cambrian.jsonld”,
“@id”: “<?php the_permalink(); ?>”,
“appid”: “你的熊掌号ID”,
“title”: “<?php the_title(); ?>”,
“images”: [“<?php echo fanly_post_imgs();?>”],
“description”: “<?php echo fanly_excerpt()?>”,
“pubDate”: “<?php echo get_the_time(‘Y-m-dTH:i:s’)?>”
}
</script>
<!–end结束–>
第二部:添加函数调用代码,找到模板中的functions.php文件,在代码后面添加上:
//Start
//获取文章/页面摘要
function fanly_excerpt($len=220){
if ( is_single() || is_page() ){
global $post;
if ($post->post_excerpt) {
$excerpt = $post->post_excerpt;
} else {
if(preg_match(‘/<p>(.*)</p>/iU’,trim(strip_tags($post->post_content,”<p>”)),$result)){
$post_content = $result[‘1’];
} else {
$post_content_r = explode(“n”,trim(strip_tags($post->post_content)));
$post_content = $post_content_r[‘0’];
}
$excerpt = preg_replace(‘#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,0}’.'((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,’.$len.’}).*#s’,’$1′,$post_content);
}
return str_replace(array(“rn”, “r”, “n”), “”, $excerpt);
}
}
//获取缩略图
function fanly_post_imgs(){
global $post;
$src = ”;
$content = $post->post_content;
preg_match_all(‘/<img .*?src=[”|’](.+?)[”|’].*?>/’, $content, $strResult, PREG_PATTERN_ORDER);
$n = count($strResult[1]);
if($n >= 3){
$src = $strResult[1][0].'”,”‘.$strResult[1][1].'”,”‘.$strResult[1][2];
}elseif($n >= 1){
$src = $strResult[1][0];
}
return $src;
}
//END
第三步: 在页面粉丝关注按钮
在移动页面中添加粉丝关注按钮,位置我们可以放在三个地方,头部、段落、尾部,这个看你个人网站的布局了,大部分人都是吸顶的,这个我不建议,因为吸顶会挡到网站的导航栏。把代码放在你对应的地方就可以了:
吸顶<script> cambrian.render(’head’)</ script>
尾部bar <script> cambrian.render(’tail’)</ script>
文章段落间bar <script> cambrian.render(’body’)</ script>
文章总结:WordPress熊掌号页面改造的方法有很多,也可以直接安装插件。插件安装多了对网站不好,会影响网站的速度,所以我建议大家手动改造一下吧。
- 赞助本站
- 微信扫一扫
-
- 加入Q群
- QQ扫一扫
-
评论