//获取文章图片 $_G['TEMP']['METAHTMLDY'] = ''; $imgs = getHtmlImages($readdata['content'], 1); $count = count($imgs); if ($count) { // 遍历图片数组,删除alt属性包含"emotion"的图片 $nonEmotionImgs = array(); foreach ($imgs as $img) { if (strpos($img['alt'], 'emotion') === false) { $nonEmotionImgs[] = $img; } } $count = count($nonEmotionImgs); // 重新获取不含"emotion"图片的数量 if ($count) { for ($i = 0; $i < $count; $i++) { $headerAddress = "https://www.lvruanhome.com/"; if (strpos($nonEmotionImgs[$i]['src'], $headerAddress) !== 0) { $readimgsurl = $headerAddress.$nonEmotionImgs[$i]['src']; } } } else { $readimgsurl = "https://www.lvruanhome.com/template/puyuetian_changable/img/error-img.png"; } } else { $readimgsurl = "https://www.lvruanhome.com/template/puyuetian_changable/img/error-img.png"; } //获取标题和页数 $readtitle = $title . (Cnum($_G['GET']['PAGE'], 1, true, 1) != 1 ? '-第' . Cnum($_G['GET']['PAGE'], 1, true, 1) . '页' : ''); //OG标签开始 $_G['TEMP']['METAHTMLDY'] .= ' <meta property="og:type" content="bbs" /> <meta property="og:image" content="' . $readimgsurl . '" /> <meta property="og:release_date" content="' . date('Y-m-d',$readdata['posttime']) . '" /> <meta property="og:title" content="' . $readtitle . '" /> <meta property="og:description" content="' . $_G['SET']['WEBDESCRIPTION'] . '" /> <meta property="og:author" content="' . $readuserdata['nickname'] . '" /> <meta property="og:bbs:replay" content="' . Cnum($readdata['fs']-1) . '" />';
这里的获取文章图片是我根据炫酷百变PC模板中的代码修改而来,由于我也不知道HadSky到底有没有这个获取文章的第一张图片的函数或者代码,所以我就直接从炫酷百变PC模板的列表显示帖子图片的代码照搬过来了,我也是稍微改进了一下这部分代码使其获取文章中的第一张图片并排除表情图片没有图片则返回默认图片。
其次,这里的OG属性我是以360的智能摘要(http://www.so.com/help/help_3_9.html)中的论坛帖子为基准
2、最后一步来了,打开HadSky的默认模板目录(“../template/default”)找到“main.hst”文件
将 {$_G['TEMP']['METAHTMLDY']} 添加到<head>和</head>之间,这样就大功告成了!
原文:https://www.lvruanhome.com/read-1152-1.html