织梦的相关文章是根据tag和文章关键词来的,不过效果不是特别的好,获取文章的数量是比较少的。对织梦系统自带的相关文章标签感兴趣的朋友,可以去看likearticle|织梦相关文章标签一文。
今天给大家分享的是只根据文章的Tag标签来调用相关文章的自定义标签,在手动填写Tag标签的情况下,效果还是非常不错的。先说一下如何给织梦系统增加自定义标签,只需要把自定义标签文件上传到\include\taglib目录即可。下面是根据Tag标签获取相关文章的自定义dede:arctag标签代码:
<?php if (!defined('DEDEINC')) exit('Request Error!'); function lib_arctag(&$ctag, &$refObj) { global $dsql; $row = "row|10"; FillAttsDefault($ctag->CAttribute->Items); extract($ctag->CAttribute->Items); $innertext = $ctag->GetInnerText(); $tcp = newDedeTagParse(); $tcp->SetNameSpace("field", "[", "]"); $tcp->LoadSource($innertext); $aid = $refObj->Fields['id']; $revalue = ''; if ($aid) { $ids = array(); $tag = array(); $dsql->Execute("f", "select tag from dede_taglist where aid = '$aid'"); while ($re = $dsql->GetArray("f")) { $tag[] = $re['tag']; } if ($tag) { foreach ($tag as $tk) { $dsql->Execute("f1", "select aid from dede_taglist where tag = '$tk'"); while ($re1 = $dsql->GetArray("f1")) { $ids[] = $re1['aid']; } } } if ($ids) { $ids = array_unique($ids); $sqa = "(" . join(",", $ids) . ")"; $query = "SELECT se.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `dede_archives` se LEFT JOIN `dede_arctype` tp ON se.typeid=tp.id WHERE se.id in $sqa limit $row"; $dsql->Execute("f2", $query); while ($row1 = $dsql->GetArray("f2")) { $row1['arcurl'] = GetFileUrl($row1['id'], $row1['typeid'], $row1['senddate'], $row1['title'], $row1['ismake'], $row1['arcrank'], $row1['namerule'], $row1['typedir'], $row1['money'], $row1['filename'], $row1['moresite'], $row1['siteurl'], $row1['sitepath']); $row1['title'] = cn_substr($row1['title'], 10); foreach ($tcp->CTags as $tid => $tt) { $tcp->Assign($tid, $row1[$tt->GetName()]); } $revalue .= $tcp->GetResult(); } } } return $revalue; }
复制以上的代码,使用Dreamweaver等专业软件保存为arctag.lib.php文件,注意和你使用的织梦DedeCMS系统编码一致。dede:arctag标签在织梦模板中的用法如下:
{dede:arctag id=10} <a href="[field:arcurl/]">[field:title/]</a> {/dede:arctag}你可以根据自己的需要,对标签进行自我拓展。