一、修改article.php,查詢數據
php
//相關文章 $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']); $art_rel_list[]=$row_art_rel; } $smarty->assign('art_rel_list', $art_rel_list);
二、建立/themes/themes_name/library/article_related.lbi
sql
<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>
三、article.dwt中調用上面的lbi
fetch
<!-- #BeginLibraryItem "/library/article_related.lbi" --><!-- #EndLibraryItem -->
四、lbi文件是能夠在管理後臺的庫項目中進行編輯的,前提是要先賦權限,以下圖ui
這時候還注意到以前的庫項目是有中文說明的,而我新增的沒有,設置的方式是在:/languages/zh_cn/admin/template.php 裏面添加以下代碼url
$_LANG['template_libs']['article_related'] = '相關文章';
修改後效果以下spa