实现根据文章的关键字获取当前文章的相关文章的方法,在文章模板中需要显示相关信息的地方插入:
<?php
if(!is_numeric($contentid)) $contentid=0;
$a = "";
$b = "";
$aa = "";
$bb = "";
if ($r[keywords]){
$keywords1 = get_sql_in($r[keywords]);
$a = $db -> select ("SELECT DISTINCT c.contentid,c.title,c.style,c.url FROM `phpcms_content` c,`phpcms_content_tag` t WHERE c.contentid=t.contentid and c.`status`=99 AND t.`tag` IN(".$keywords1.") and c.contentid!=".$contentid." ORDER BY c.listorder DESC,c.inputtime DESC,c.contentid desc limit 0,5");
if ($a){
foreach($a as $r){
$aa .= "<dd><a href="".$r[url]."" target="_blank">".$r[title]."</a></dd>";
}
?>
<dl class="xiangguan">
<dt>相关阅读:</dt>
<?php echo $aa;?>
</dl>
<?php
}
}
$b = $db -> select ("SELECT DISTINCT b.specialid,b.url,b.title FROM `phpcms_special_content` a,`phpcms_special` b WHERE a.contentid=".$contentid." and b.specialid=a.specialid ORDER BY b.listorder DESC,b.createtime desc limit 0,5");
if ($b){
foreach($b as $r){
$bb .= "<dd><a href="".$r[url]."" target="_blank">".$r[title]."</a></dd>";
}
?>
<dl class="xiangguan">
<dt>相关专题:</dt>
<?php echo $bb;?>
</dl>
<?php
}
?>