当前位置 : 主页 > 建站教程 > dedecms >

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

来源:互联网 收集:自由互联 发布时间:2021-12-23
织梦内容页做熊掌号,图片这一块,有文章内容图片就输出3张,没有就不输出,自动加逗号隔开,在 /include/extend.func.php 这个文件最下面加入一个函数 /** * 文章内容提取图片(多张)自定

织梦内容页做熊掌号,图片这一块,有文章内容图片就输出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-d\TH:i:s',@me)"/}"
}
</script>

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

上一篇:织梦不能自动提取缩略图解决方法
下一篇:没有了
网友评论
相关栏目