ecshop增加相关文章栏目功能

1、修改article.php文件,增加如下代码
    /* 相关文章 by ECShop.cx */
    $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 -->
相关热词搜索:ecshop文章栏目相关文章

本文原创地址:https://www.ecshop.cx/article-3.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉

文章评论

暂无评论,来发表一个吧

发表 取消
ECSHOP插件网微信客服edait_cn