最近访客
百度未收录

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

织梦内容页做熊掌号,图片这一块,有文章内容图片就输出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

温馨提示: 本文最后更新于2022/10/20 11:02:27。若文章内容或图片失效,请 留言联系站长反馈!
!
也想出现在这里? 联系我们
创意广告
© 版权声明
THE END
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容