LSRONG-双荣设计
扫描二维码添加QQ好友

扫一扫二维码,加我QQ

ecshop如何让文章添加关联文章

2016-03-27 11:03:06ecshop常见问题

今天有客户问到如何添加关联文章,下面里奥模板中心(www.68ecshop.com)教程教大家如何操作(以默认模板为例):

 

1.首先执行SQL语句:

INSERT INTO  `ecs_shop_config` (`id` , `parent_id` , `code` , `type` , `store_range` , `store_dir` , `value` , `sort_order`)
VALUES ( '399',  '3',  'article_related',  'select',  '0,1',  '',  '1',  '1');
ALTER TABLE  `ecs_article` ADD INDEX (  `keywords` );

2.需要增加的新文件:/themes/default/library/article_related.lbi

将以下代码复制另存为article_related.lbi,然后上传到/themes/default/library/目录下

(要注意这个文件里面的编码,我的编码是charset=gbk,这里你要改成你程序文件的编码,否则会乱码。

如果编码正确文件出现乱码,可以新建记事本,复制代码到记事本里面,把编码改成你的编码后,后缀名改为.lbi,另存为lbi文件就不会乱码了!)
 

<?php

$sql_where = " where is_open=1 and article_id != '" .$GLOBALS['article']['article_id'] . "' ";

if ( $GLOBALS['_CFG']['article_related'] == '1' )
{
$sql_where .= " and cat_id = '" . $GLOBALS['article']['cat_id'] . "' ";
}
elseif ( $GLOBALS['_CFG']['article_related'] == '0' )
{
//通过关键字关联
if ($GLOBALS['article']['keywords'])
{
  $GLOBALS['article']['keywords'] = str_replace(",",  "," , $GLOBALS['article']['keywords']);
  $key_list=explode(",", $GLOBALS['article']['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 " . $GLOBALS['ecs']->table('article') . " $sql_where limit 0,10 ";
//echo $sql;
$res_art_rel=$GLOBALS['db']->query($sql);
while ( $row_art_rel = $GLOBALS['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;
}
$GLOBALS['smarty']->assign('art_rel_list', $art_rel_list);
?>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<style>
.art_rel_tit{clear:both;width:98%;font-size:17px;font-weight:bold;padding:8px 0; margin-top:15px; text-align:left; border-bottom:1px solid #ccc;}
.art_rel_box{width:98%;padding:8px 0;}
.art_rel_box ul{width:100%;}
.art_rel_box ul li{float:left;width:300px;height:25px;}
.art_rel_box ul li a{text-decoration:none;color:#000;}
.art_rel_box ul li a:hover{text-decoration:underline;color:#ff3300;}
</style>
<div class="art_rel_tit">相关文章</div>
<div class="art_rel_box">
<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>
<div style="clear:both;"><br></div>


3、需要修改的文件:/themes/default/article.dwt


搜索 “  <!-- {if $article.content } -->{$article.content}<!-- {/if} --> ” ,

在下面加上以下代码:


<!-- #BeginLibraryItem "/library/article_related.lbi" --><!-- #EndLibraryItem -->



4、需要修改的文件:/languages/zh_cn/admin/shop_config.php,

 

在文件的最后部分加上以下代码:

$_LANG['cfg_name']['article_related'] = '相关文章来源';
$_LANG['cfg_desc']['article_related'] = '设定文章详情页 “相关文章” 如何关联';
$_LANG['cfg_range']['article_related'][0] = '通过关键字关联';
$_LANG['cfg_range']['article_related'][1] = '通过文章类别关联';

即可!

文章关键词