dedecms是常用的文章管理系统,今天小白分享是的资讯详情页面进行熊掌号改造的代码。
资讯页面的head部分代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{dede:field.title/}-方圆模板</title>
<meta name="keywords" content="{dede:field.keywords/}" />
<meta name="description" content="{dede:field.description function='html2text(@me)'/}" />
<link rel="canonical" href="http://www.sdfymb.com{dede:field name='arcurl'/}" />
<script src="http://msite.baidu.com/sdk/c.js?appid=1634404368209099"></script>
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "http://www.sdfymb.com{dede:field name='arcurl'/}",
"appid": "1634404368209099",
"title": "{dede:field.title/}-方圆模板",
"images": [{dede:field.body function=getbodypics(@me,3)/}],
"pubDate": "{dede:field.pubdate function="MyDate('Y-m-d',@me)"/}T{dede:field.pubdate function="MyDate('H:i:s',@me)"/}"
}
</script>
<link href="/skin/css/style.css" rel="stylesheet" type="text/css" />
</head>
然后修改/include/extend.func.php文件,在文件最下面添加:
// 获取文章主题图片
function getbodypics($string, $num)
{
preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/",$string,$matches);
$imgsrc_arr = array_unique($matches[3]);
$count = count($imgsrc_arr);
$i = 0;
if($count>2){
foreach($imgsrc_arr as $imgsrc)
{
if($i == $num) break;
if($i == 2){$result .= "\"http://www.sdfymb.com$imgsrc\"";break;}
$result .= "\"http://www.sdfymb.com$imgsrc\",";
$i++;
}
}else{
foreach($imgsrc_arr as $imgsrc)
{
if($i == 1) break;
$result .= "\"http://www.sdfymb.com$imgsrc\"";
$i++;
}
}
return $result;
}
例如:页面http://www.sdfymb.com/news/709.html,其展现代码为:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>木质建筑圆模板优势及安装施工 柱子比钢模板支模更便捷-方圆模板</title>
<meta name="keywords" content="建筑圆模板" />
<meta name="description" content="木质建筑圆模板已经取代传统的 建筑圆模板 称为圆形建筑支模施工的优选,那么为什么选用方圆建筑模具加工生产的木质圆柱模板呢?其对比传统柱子钢模板有哪些优势呢?今天小编就为您介绍" />
<link rel="canonical" href="http://www.sdfymb.com/news/709.html" />
<script src="http://msite.baidu.com/sdk/c.js?appid=1634404368209099"></script>
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "http://www.sdfymb.com/news/709.html",
"appid": "1634404368209099",
"title": "木质建筑圆模板优势及安装施工 柱子比钢模板支模更便捷-方圆模板",
"images": ["http://www.sdfymb.com/uploads/image/2019/1-191111095352945.jpg","http://www.sdfymb.com/uploads/image/2019/1-191111095411c2.jpg","http://www.sdfymb.com/uploads/image/2019/1-191111095432P2.jpg"],
"pubDate": "2019-11-11T09:46:39"
}
</script>
<link href="/skin/css/style.css" rel="stylesheet" type="text/css" />
</head>