作者/整理:锦皓工作室 时间: 2017-11-10 浏览:
熊掌号最近很火啊,配置很简单,但帝国的内容页图片调用不太好搞,需要将newstext里面的图片地址取出来;
帝国CMS配置代码如下,需要把ID和域名换成自己的。
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "[!--titleurl--]",
"appid": "百度给的熊掌ID",
"title": "[!--pagetitle--]",
"images": [
<?php
$str=$navinfor['newstext'];
$str = str_replace('http://www.tengbenyueji.com/d/file/','/d/file/',$str);//把图片格式统一化,如果是远程图片需要注意。
$str = str_replace('/d/file/','http://www.tengbenyueji.com/d/file/',$str);//把相对地址改成绝对地址;
preg_match_all('/http:.*?(jpg|gif|png|bmp)/' ,$str, $img);//取出图片地址;
echo '"'.$img[0][1].'"'.',';//第一张
echo '"'.$img[0][2].'"'.',';//第二张
echo '"'.$img[0][3].'"';//第三张
?>
],
"description": "[!--smalltext--] ",
"pubDate": "<?=date("Y-m-d",$navinfor['newstime'])?>T<?=date("H:i:s",$navinfor['newstime'])?>"
}
</script>
<script src="//msite.baidu.com/sdk/c.js?appid=百度给的熊掌ID"></script>