欢迎来到元素模板ys720.com,本站提供专业的织梦模板PBOOTCMS模板网站模板网站修改/网站仿站
当前位置:主页 > 程序教程 > ECSHOP教程 >
ECSHOP教程

ecshop如何增加相关文章栏目功能

(元素模板) / 2023-02-16 12:19
如何让你的ecshop程序增加 相关文章的栏目功能呢?
元素模板为您解答:
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>
3、打开article.dwt文件加入调用上面的lbi
<!-- #BeginLibraryItem "/library/article_related.lbi" --><!-- #EndLibraryItem -->
Copyright @ 2013-2021 元素模板 www.ys720.com All Rights Reserved. 版权所有 元素模板 www.ys720.com