织梦内容页做熊掌号有图片就输出三张,没有就不输出

织梦内容页做熊掌号,图片这一块,有文章内容图片就输出3张,没有就不输出,自动加逗号隔开,在 /include/extend.func.php 这个文件最下面加入一个函数

 /**   
*  文章内容提取图片(多张)自定义输出   
*   星空站长网    
* @access    public   
* @param     string  $string  文档内容   
* @param     string  $num  输出几张   
* @return    string   
*/  
if(!function_exists('getBodypics'))  {  function getBodypics($string, $num)  {  global $cfg_basehost;  preg_match_all("/<img([^>]*)s*src=('|")([^'"]+)('|")/",$string,$matches);  $imgsrc_arr = array_unique($matches[3]);  $count = count($imgsrc_arr);  $i = 0;  $result = '';  foreach($imgsrc_arr as $imgsrc)  {  if($i == $num) break;  $result .= ($result=='' ? '"'.$cfg_basehost.$imgsrc.'"' : ','.'"'.$cfg_basehost.$imgsrc.'"');  $i++;  }  return $result;  }  }

然后在织梦内容页模板在前面加入

<link rel="canonical" href="{dede:global.cfg_basehost/}{dede:field.id runphp=yes}$result=GetOneArchive(@me);@me=$result['arcurl'];{/dede:field.id}"> <script src="//msite.baidu.com/sdk/c.js?appid=1608633444348086"></script> <script type="application/ld+json"> { "@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld", "@id": "{dede:global.cfg_basehost/}{dede:field.id runphp=yes}$result=GetOneArchive(@me);@me=$result['arcurl'];{/dede:field.id}", "appid": "1608633444348086", "title": "{dede:field.title/}", "images": [{dede:field.body function=getBodypics(@me,3)/}], "description": "{dede:field.description function=html2text(@me)/}", "pubDate": "{dede:field.pubdate function="MyDate('Y-m-dTH:i:s',@me)"/}" } </script>

如果网站有独立手机端,把{dede:global.cfg_basehost/}这个改为手机域名,上面代码中那2个id 608633444348086改成你自己的熊掌号id

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
广告位招租919838898
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索