其实这个问题,之前我发过JS版本的教程,比较复杂,有兴趣的可以去看看《熊掌号搜索结果出图怎么弄?我教你》,今天发现有人搜dede版本的,于是,我就捣鼓了一下。具体的就不多说了,很简单,跟我坐两个步骤就好。
1.找到你网站根目录下的“include”目录,找到“extend.func.php”这个文件,打开,在最后一行下面,空白的地方加上下面这段代码:
function santu($aid)
{
global $dsql;
$body=$dsql->GetOne("Select body From `dede_addonarticle` where aid='$aid'");
$web=$dsql->GetOne("Select value From `dede_sysconfig` where varname='cfg_basehost'");
$chuan=$dsql->GetOne("Select senddate,title From `dede_archives` where id='$aid'");
$title = $chuan["title"];
$timen = date("Y-m-d",$chuan["senddate"]);
$times = date("H:i:s",$chuan["senddate"]);
$time = $timen.'T'.$times;
$sss = $body["body"];
$webs = $web["value"];
$preg = "/<img.*?src=['"](.+?)['"].*?>/i";
preg_match_all($preg,$sss,$zurl);
$cs=count($zurl[1]);
$images='';
if($cs<3)
{
$images='"'.$webs.$zurl[1][0].'"';
}
else
{
for($i=0;$i<3;$i++)
{
$images .= $images!=''?',"'.$webs.$zurl[1][$i].'"':'"'.$webs.$zurl[1][$i].'"';
}
}
$url=$webs.GetCurUrl();
echo '<script type="application/ld+json">{"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld","@id": "'.$url.'","appid": "1596714490639073","title": "'.$title.'","images": ['.$images.'],"pubDate": "'.$time.'"}</script>';
}
2.在你的文章模板处,加入{dede:php}santu($aid);{/dede:php},放什么地方都行,建议放在后面,有多后就多后,但一定要在前面
3.系统设置的模板引擎禁用标签里要把php去掉,具体路径,后台,系统设置-》其他选项-》模板引擎禁用标签,里面如果填有php,就删除,留空白。
4.系统设置的页面,“站点根网址”这里,一定要填好!比如https://www.9wmiao.com,最后面不要加"/",如果你的网站是https的就写https,不是的就写http!
然后就没有然后了!至于,是三图,还是一张图,就看你自己文章里的图片数量了!注意!是文章正文内容里面!
发表评论