ECshop文章内容页按关键字获取相关文章
ecshop模板网 / 2013-12-14
在ecshop的 acticle.php 最下面加入如下代码
- function article_related_Keywords($ids)
- {
- $sql = 'SELECT article_id,keywords FROM '. $GLOBALS['ecs']->table('article') .'WHERE article_id = '.$ids;
- $res = $GLOBALS['db']->query($sql);
- $row = $GLOBALS['db']->fetchRow($res);
- $keyword = $row['keywords'];
- return $keyword;
- };
- function article_related_art($keyword)
- {
- $sql = 'SELECT article_id,keywords,cat_id, title, open_type,content,file_url,add_time FROM '. $GLOBALS['ecs']->table('article') .'WHERE cat_id>6 AND content LIKE "%%'.$keyword.'%%"limit 0,10';
- $res = $GLOBALS['db']->query($sql);
- $arr = array();
- while ($row = $GLOBALS['db']->fetchRow($res))
- {
- $arr[$row['article_id']]['article_id'] = $row['article_id'];
- $arr[$row['article_id']]['title'] = $row['title'];
- $arr[$row['article_id']]['file_url'] = $row['file_url'];
- $arr[$row['article_id']]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
- $arr[$row['article_id']]['url'] = $row['open_type'] != 1 ?
- build_uri('article', array('aid'=>$row['article_id']), $row['title']) : trim($row['file_url']);
- };
- return $arr;
- }
查找
- $smarty->assign('promotion_info', get_promotion_info());
在下方添加模版调用代码
- $smarty->assign('related_art', article_related_art(article_related_Keywords($article_id)));
在模版相应位置调用
- {foreach from=$related_art item=article_related_date}
- <li>• <a href="{$article_related_date.url}" target="_blank">{$article_related_date.title}</a></li>
- {/foreach}