织梦DEDECMS资讯页面熊掌号改造
织梦dedecms文章详情页面进行熊掌号改造代码:
<link rel="canonical" href="http://www.sdfymb.com{dede:field name='arcurl'/}" />
<script src="http://msite.baidu.com/sdk/c.js?appid=1634404368209099"></script>
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "http://www.sdfymb.com{dede:field name='arcurl'/}",
"appid": "1634404368209099",
"title": "{dede:field.title/}-方圆模板",
"images": [{dede:field.body function=getbodypics(@me,3)/}],
"pubDate": "{dede:field.pubdate function="MyDate('Y-m-d',@me)"/}T{dede:field.pubdate function="MyDate('H:i:s',@me)"/}"
}
</script>
但是在织梦原有的程序中,是不存在getbodypics函数的,我们需要修改文件:/include/extend.func.php,
在文件的最后添加:
// 获取文章主题图片function getbodypics($string, $num) { preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/",$string,$matches); $imgsrc_arr = array_unique($matches[3]); $count = count($imgsrc_arr); $i = 0; if($count>2){ foreach($imgsrc_arr as $imgsrc) { if($i == $num) break; if($i == 2){$result .= "\"http://www.sdfymb.com$imgsrc\"";break;} $result .= "\"http://www.sdfymb.com$imgsrc\","; $i++; } }else{ foreach($imgsrc_arr as $imgsrc) { if($i == 1) break; $result .= "\"http://www.sdfymb.com$imgsrc\""; $i++; } } return $result;}
到此就能完整的实现DEDECMS资讯详情页面的熊掌号改造!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。