织梦内容页做熊掌号,图片这一块,有文章内容图片就输出3张,没有就不输出,自动加逗号隔开,在 /include/extend.func.php 这个文件最下面加入一个函数
05 | * @param string $string 文档内容 |
06 | * @param string $num 输出几张 |
09 | if(!function_exists('getBodypics')) |
11 | function getBodypics($string, $num) |
14 | preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/",$string,$matches); |
15 | $imgsrc_arr = array_unique($matches[3]); |
16 | $count = count($imgsrc_arr); |
19 | foreach($imgsrc_arr as $imgsrc) |
22 | $result .= ($result=='' ? '"'.$cfg_basehost.$imgsrc.'"' : ','.'"'.$cfg_basehost.$imgsrc.'"'); |
|
然后在织梦内容页模板在</head>前面加入
01 | <link rel="canonical" href="{dede:global.cfg_basehost/}{dede:field.id runphp=yes}$result=GetOneArchive(@me);@me=$result['arcurl'];{/dede:field.id}"> |
02 | <script src="//msite.baidu.com/sdk/c.js?appid=1608633444348086"></script> |
03 | <script type="application/ld+json"> |
06 | "@id": "{dede:global.cfg_basehost/}{dede:field.id runphp=yes}$result=GetOneArchive(@me);@me=$result['arcurl'];{/dede:field.id}", |
07 | "appid": "1608633444348086", |
08 | "title": "{dede:field.title/}", |
09 | "images": [{dede:field.body function=getBodypics(@me,3)/}], |
10 | "description": "{dede:field.description function=html2text(@me)/}", |
11 | "pubDate": "{dede:field.pubdate function="MyDate('Y-m-d\TH:i:s',@me)"/}" |
|
如果网站有独立手机端,把{dede:global.cfg_basehost/}这个改为手机域名,上面代码中那2个id 608633444348086改成你自己的熊掌号id