婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 網站建設 > 建站知識 > 織夢內容頁做熊掌號有圖片就輸出三張,沒有就不輸出

織夢內容頁做熊掌號有圖片就輸出三張,沒有就不輸出

POST TIME:2021-05-24 02:49

織夢內容頁做熊掌號,圖片這一塊,有文章內容圖片就輸出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



收縮
  • 微信客服
  • 微信二維碼
  • 電話咨詢

  • 400-1100-266
主站蜘蛛池模板: 涟源市| 桃江县| 裕民县| 福海县| 玛沁县| 昌江| 兴和县| 丰顺县| 郓城县| 清水河县| 安达市| 康马县| 麻城市| 开化县| 宿迁市| 天门市| 仁布县| 普格县| 将乐县| 漠河县| 旅游| 灌南县| 蒙山县| 鹤庆县| 林州市| 富源县| 荣成市| 宁城县| 呼玛县| 崇礼县| 白沙| 德化县| 高碑店市| 星子县| 交口县| 大渡口区| 泰州市| 将乐县| 通州区| 太白县| 洪洞县|