
1、申请百度的熊掌号
2、绑定自己的网站(必须是自适应网站或者手机站,pc端链接是不支持的哦)
3、在内容页(包括产品和新闻)模版的</head>标签前添加号主页中提供的JSON代码
至于织梦相应的参数怎么调用看下边代码,这我网站用的代码,亲测无误
<script type="application/ld+json"> {"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "{dede:global.cfg_basehost/}{dede:field name='arcurl'/}",
"appid": "你的熊掌号ID",
"title": "{dede:field.title/}",
"images": [
"{dede:global.cfg_basehost/}{dede:field.litpic/}"
],
"pubDate": "{dede:field.pubdate function="MyDate('Y-m-d\TH:i:s',@me)"/}"
}
</script>
注:由于网站采用的是相对连接,所以提交数据中{dede:global.cfg_basehost/}是调用的网站根目录链接,如果是绝对链接的话就可以直接删掉{dede:global.cfg_basehost/}即可
WordPress添加熊掌号的json_id结构化数据代码如下:
PHP代码,用于获取文章摘要内容,代码添加在当前主题functions.php中
<?php//获取文章/页面摘要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("\r\n", "\r", "\n"), "", $excerpt)
}}?>
json_id数据,添加在head头部中:
<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 catch_that_image() ?>"],
"description": "<?php echo fanly_excerpt()?>",
"pubDate": "<?php echo get_the_time('Y-m-d\TH:i:s')?>",
}</script>
appid就是熊掌号ID,自己修改一下即可。
以上代码来源于泪雪博客:网页链接 版权归属原作者
获取ajax数据有两种方式: 定义和参数相同的变量,可以获得相对应的名字 可以通过request来获取相应的值 有的时候还有可能获取一些cookie和session的值,这个可以用其相对应的方法来获取行系统优化。对于已经发生的问题,可以看看下
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)