© 2002-2018 最模板 zuimoban.com 版权所有,并保留所有权利。
ecshop模板网,专注ecshop模板制作、ecshop二次开发服务!
1、修改article.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="sel ect 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);
2、创建/themes/themes_name/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>
3、article.dwt中调用上面的lbi
<!-- #BeginLibraryItem "/library/article_related.lbi" --><!-- #EndLibraryItem -->
4、lbi文件是可以在管理后台的库项目中进行编辑的,前提是要先赋权限,如下图
这时候还注意到之前的库项目是有中文说明的,而我新增的没有,设置的方式是在:/languages/zh_cn/admin/template.php 里面添加如下代码
1 | $_LANG['template_libs']['article_related'] = '相关文章'; |
修改后效果如下