织梦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详情页面熊掌号代码的改造。
原文:https://www.cnblogs.com/fymuban/p/11834643.html