加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > Dedecms > 正文

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

发布时间:2020-12-14 04:23:25 所属栏目:Dedecms 来源:网络整理
导读:织梦内容页做熊掌号,图片这一块,有文章内容图片就输出3张,没有就不输出,自动加逗号隔开,在 /include/extend.func.php 这个文件最下面加入一个函数 /** * 文章内容提取图片(多张)自定义输出 * 织梦模板 网 * @access public * @param string $string 文

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

?

然后在织梦内容页模板在</head>前面加入

<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

上一篇:织梦第三方响应式后台辅助插件不显示新模块和插件的解决方法

下一篇:织梦不能自动提取缩略图解决方法

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读