dedecms如何利用tag来调取相关文章

2019-03-3022:16:47网站建设与开发Comments1,659 views字数 1936阅读模式

DEDE文章里,很多人都是只填了TAG,而没有填写关键字,更不要说手动去设置其相关文章了。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

所以,就希望有一个功能,可以列出当前文章的按TAG进行相关匹配的文章,作为其相关文章。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

例如:A文章的tag是“证券 金融 次贷”,B文的TAG是“美女 时尚”,C文的TAG是“美女 次贷”,D文的tag是“证券 贬值”,那么A文章用次此修改后得到的相关文章就是C和D,B文的相关文章是C,C文的相关文章是A和B,D文相关文章是A文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

修改方法为以下两步(已在DEDE5.1 GBK版上调试通过,如果你是要修改UTF-8版本,切记不要用记事本打开DEDE自带的文件):文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

第一步:在include\文件的最后?>之前,插入以下函数代码文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

function ShowTagLikeArc_by_id($titleLen,$rowCount,$typeid,$aid){文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$dsql = new DedeSql(false);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

if ($typeid!="0") $sql = TypeGetSunID($typeid,$dsql);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

else $sql =" 1=1 ";文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

//找到所有的tag id文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$query="Select tid from #@__tag_list where aid=$aid";文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$dsql->SetQuery($query);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$dsql->Execute();文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

while($row=$dsql->GetObject()){文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$kwsqlarr[] = " ('".$row->tid."') ";文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$where = implode(' OR ',$kwsqlarr);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

if (trim($where)=="") $where=" 1<>1 ";文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$sql="Select DISTINCT tp.namerule,tp.typedir,#@__archives.* From #@__tag_list tl left join #@__archives on tl.aid=#@__archives.ID left join #@__arctype tp on #@__archives.typeid=tp.ID where {$sql} and ( $where) and #@$aid order by #@__archives.litpic desc,#@__archives.click desc"; //排序按有缩略图、点击率高的排名靠前文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$dsql->SetQuery($sql);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$dsql->Execute();文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$ss="";文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$i=0;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

while($row=$dsql->GetObject()){文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$url=GetFileUrl($row->ID,$row->typeid,$row->senddate,$row->title,$row->ismake,$row->arcrank,$row->namerule,$row->typedir,$row->money);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$ss=$ss."<li><a href='".$url."' title='".$row->title."'>";文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

if ($titleLen!=0) $ss=$($row->title,$titleLen);文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

else $ss=$ss.$row->title;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$ss=$ss."</A></LI>";文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

$i++;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

if (($rowCount!=0)&&($i>=$rowCount)) return $ss;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

if ($ss=="") $ss="暂无相关文章";文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

return $ss;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

第二步:在文章内容页模板(通常是)里,加入调用此函数的标签:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

例如:{dede:field name='ID' function='ShowTagLikeArc_by_id(20,10,0,@me)' /}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

这个标签的意思就是:从所有栏目里,查找本篇文章的tag相关文章,一共找10条,标题显示最长为20个字文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

又如:{dede:field name='ID' function='ShowTagLikeArc_by_id(0,0,2,@me)' /}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

这个标签的意思就是:从ID为2栏目及其所有子栏目里,查找本篇文章的tag相关文章,不限制文章数量,标题显示不限字数文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

附注:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

1 生成出来的相关文章HTML形如:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

<li><a href="/html/xxxx/">C文标题</a></li>文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

<li><a href="/html/xxxx/">D文标题</a></li>文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

如果你的模板有样式方面的要求,可自行调整代码里的<li>部分文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

2 目前得到的相关文章,是按有缩略图且点击率高的拍列靠前,如需有自己的排序要求,请修改代码里的order by #@__archives.litpic desc,#@__archives.click desc部分,不懂的请查阅跟帖或跟贴提问,其他网友代为回答,我将给予一定热心助人奖励文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10916.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/10916.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定