元素模板为您解答:
1、修改article.php文件,增加如下代码
/* 相关文章 by YS720.COM */ $sql_where = " WHERE is_open = 1 AND article_id != '" .$_REQUEST[id]. "' "; $keywords = str_replace(",", "," , $article['keywords']); $key_list = explode(",", $keywords); $key_id = 0; $sql_or = ""; foreach ($key_list as $keyword) { $sql_or .= $key_id ? " OR " : ""; $sql_or .= " keywords LIKE '%" . trim($keyword) . "%' "; $key_id++; } $sql_or = " ( ". $sql_or ." ) "; $sql_where .= " AND " . $sql_or ; $sql = "SELECT article_id, cat_id, title, open_type, file_url FROM " . $ecs->table('article') . " $sql_where LIMIT 0,10 "; $res_art_rel = $db->query($sql); while ($row_art_rel = $db->fetchRow($res_art_rel)) { $row_art_rel['url']=$row_art_rel['open_type'] != 1 ? build_uri('article', array('aid'=>$row_art_rel['article_id']), $row_art_rel['title']) : trim($row_art_rel['file_url']); $sql = "SELECT cat_type FROM " . $ecs->table('article_cat') . " WHERE cat_id = '$row_art_rel[cat_id]'"; $cat_type = $db->getOne($sql); if ($cat_type == 2 || $cat_type == 3 || $cat_type == 4) { /* 过滤系统保留分类 */ unset($art_rel_list); } $art_rel_list[] = $row_art_rel; } $smarty->assign('art_rel_list', $art_rel_list);2、创建/themes/default/library/article_related.lbi文件
<div class="related-box"> <div class="hd"> <h3>相关文章</h3> </div> <ul> <!--{foreach from=$art_rel_list item=art_rel}--> <li><a href="{$art_rel.url}" target="_blank">{$art_rel.title}</a></li> <!--{/foreach}--> </ul> </div>
<!-- #BeginLibraryItem "/library/article_related.lbi" --><!-- #EndLibraryItem -->