織夢內容頁做熊掌號,圖片這一塊,有文章內容圖片就輸出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
新聞熱點
疑難解答