DEDE的相關(guān)文章完全不相關(guān),有朋友在DEDE官方放出根據(jù)TAG顯示相關(guān)文章,也是很不錯(cuò),可惜我在根據(jù)那邊文章改DEDE代碼后老是不行,可能是能力有限,當(dāng)然也有可能是代碼有問(wèn)題
現(xiàn)在終于出了解決辦法:
1 在 inc_functions.php 最后?>前 加上
//查詢指定欄目里包含相應(yīng)關(guān)鍵字的文章,并列出 //參數(shù)說(shuō)明:$showImg 是否顯示縮略圖,0表示不顯示,1表示顯示 // $titleLen 標(biāo)題長(zhǎng)度,0表示無(wú)限 // $rowCount 輸出行數(shù),0表示無(wú)限 // $typeid 欄目ID,0表示所有欄目 // $keyWord 關(guān)鍵字,字符串 function ShowKeyWordArc($showImg,$titleLen,$rowCount,$typeid,$keyWord){ $dsql = new DedeSql(false); $sql = TypeGetSunID($typeid,$dsql); //關(guān)鍵字分詞技術(shù) $ks = explode(" ",$keyWord); foreach($ks as $k){ $k = trim($k); if ($k!="") { $kwsqlarr[] = " (xkzzz_archives.title like '%$k%') "; //$kwsqlarr[] = " (xkzzz_archives.keywords like '%$k%') "; //如果需要相關(guān)到其它文章的關(guān)鍵字,解除此行注釋 } } $where = implode(' OR ',$kwsqlarr); $sql="Select tp.namerule,tp.typedir,xkzzz_full_search.aid,xkzzz_full_search.url,xkzzz_archives.* From xkzzz_full_search left join xkzzz_archives on xkzzz_full_search.aid=xkzzz_archives.ID left join xkzzz_arctype tp on xkzzz_archives.typeid=tp.ID where {$sql} and ((xkzzz_archives.title like '%".$keyWord."%') or $where) order by xkzzz_full_search.aid desc"; $dsql->SetQuery($sql); $dsql->Execute(); $ss=""; $i=0; while($row=$dsql->GetObject()){ $url=GetFileUrl($row->ID,$row->typeid,$row->senddate,$row->title,$row->ismake,$row->arcrank,$row->namerule,$row->typedir,$row->money); if ($showImg==0){ $ss=$ss."<LI><a href='".$url."' target=_blank>"; if ($titleLen!=0) $ss=$ss.cn_substr($row->title,$titleLen); else $ss=$ss.$row->title; $ss=$ss."</A></LI>"; }else{ $ss=$ss."<LI><span class='sjdqimggl'><a href='".$url."' target=_blank>";
if ($row->litpic!="") $ss=$ss."<img src='".$row->litpic."' alt='".$row->title."' />"; else $ss=$ss."<img src='/images/titl.gif'/>"; $ss=$ss."</a></span><span class='sjdqtxttl'><a href='".$url."' target=_blank>"; if ($titleLen!=0) $ss=$ss.cn_substr($row->title,$titleLen); else $ss=$ss.$row->title; $ss=$ss."</A></span></LI>"; } $i ; if (($rowCount!=0)&&($i>=$rowCount)) return $ss; } return $ss; }
2 放在文章模板頁(yè)內(nèi)
{dede:field name=’keywords’ function=’ShowKeyWordArc(0,32,10,0,”@me”)’/}
就表示是取所有欄目?jī)?nèi)的相關(guān)文章(與當(dāng)前文章的關(guān)鍵字相關(guān)),標(biāo)題長(zhǎng)度最大32,最多顯示10條,不顯示縮略圖
或
{dede:field name=’keywords’ function=’ShowKeyWordArc(0,32,10,0,”高三 語(yǔ)文”)’/}
可以找到標(biāo)題里,含有“高三 語(yǔ)文”,或者含有“高三”或“語(yǔ)文”的文章
例如,這一段:
相關(guān)文章 {dede:likeart titlelen=’24′ row=’10′}
[field:textlink/]< >
{/dede:likeart}
就改成:
相關(guān)文章 {dede:field name=’keywords’ function=’ShowKeyWordArc(0,32,10,0,”@me”)’/}