码迷,mamicode.com
首页 > 其他好文 > 详细

ecshop教程之首页完美调用最新评论

时间:2015-08-30 14:20:49      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

第一步:建立一个名为index_comments.lbi的库文件放到模板下面的library文件夹下

第二步:把新建立的库文件在index.dwt中调用
           我的是把最新评论放到了销售排行下面那么就是把

<!-- #BeginLibraryItem "/library/index_comments.lbi" -->  <!-- #EndLibraryItem -->加入到<!-- #BeginLibraryItem "/library/top10.lbi" -->  <!-- #EndLibraryItem -->后面。

 



第三步:打开文件languages/zh_cn/admin/template.php
在64行---127行之间加入

$_LANG[template_libs][index_comments] = 最新评论;


第四步:打开\admin\includes\lib_template.php  我是在首页调用的所以只要在这里添加就行了。加粗为添加部分

index => array(
        /library/ur_here.lbi => 0,
/library/index_comments.lbi => 0,
        /library/search_form.lbi => 0,
        /library/member.lbi => 0,
        /library/new_articles.lbi => 0,
        /library/category_tree.lbi => 0,
        /library/top10.lbi => 0,
        /library/invoice_query.lbi => 0,
        /library/recommend_best.lbi => 3,
        /library/recommend_new.lbi => 3,
        /library/recommend_hot.lbi => 3,
        /library/recommend_promotion.lbi => 4,
        /library/group_buy.lbi => 3,
        /library/auction.lbi => 3,
        /library/brands.lbi => 3,
        /library/promotion_info.lbi => 0,
        /library/cart.lbi => 0,
        /library/order_query.lbi => 0,
        /library/email_list.lbi => 0,
        /library/vote_list.lbi => 0
    ),

 


第五步:打开\themes\BigSale(这里是我用的模板)下的libs.xml(同上我只是在首页调用了所以只改首页模板就可以)加粗为添加部分

<file name="index.dwt">
    <region name="通栏广告位"/>
    <region name="左边区域">
      <lib>category_tree</lib>
      <lib>top10</lib>
   <lib>index_comments</lib>
      <lib>promotion_info</lib>
      <lib>order_query</lib>
      <lib>invoice_query</lib>
      <lib>email_list</lib>
      <lib>vote_list</lib>
    </region>


至此可以完美实现首页调用最新评论。不必再因为重新设置模板而被刷新烦恼

下面是index_comments.lbi的内容:

<?php
if(!function_exists("get_comments")){
function get_comments($num)
{
   $sql = SELECT a.*,b.goods_id,b.goods_thumb,b.goods_name FROM . $GLOBALS[ecs]->table(comment) .
             AS a,. $GLOBALS[ecs]->table(goods) .AS b WHERE a.status = 1 AND a.parent_id = 0 and a.comment_type=0 and a.id_value=b.goods_id .
             ORDER BY a.add_time DESC;
  if ($num > 0)
  {
   $sql .=  LIMIT  . $num;
  }
  //echo $sql;
       
  $res = $GLOBALS[db]->getAll($sql);
  $comments = array();
  foreach ($res AS $idx => $row)
  {
   $comments[$idx][add_time]       = local_date($GLOBALS[_CFG][time_format], $row[add_time]);
   $comments[$idx][content]       = $row[content];
   $comments[$idx][id_value]       = $row[id_value];
   $comments[$idx][goods_thumb]  = get_image_path($row[goods_id], $row[goods_thumb], true);
   $comments[$idx][goods_name]       = $row[goods_name];
  }
  return $comments;
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--评论 -->      
<?php
   $this->assign(my_comments,get_comments(6)); //
?>
<div class="module_2">
      <h2 class="modTitle tl">
         <span class="L"></span><span class="R"></span>最新评论</h2>
<!--{foreach from=$my_comments item=comments}-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" style=" border-bottom:1px #ccc dashed;">
  <tr>
    <td width="73" height="70" align="center"><a href="goods.php?id={$comments.id_value}" target="_blank"><img src="{$comments.goods_thumb}" border="0" width="60" height="60" style=" border:1px #CCCCCC solid;"/></a></td>
    <td width="473" align="left" valign="top">
<div style="height:3px; overflow:hidden;">&nbsp;</div>
<div><a href="goods.php?id={$comments.id_value}" target="_blank"><font style=" color:#FF0000; font-size:14px;">{$comments.goods_name}</font></a></div>
<div>{$comments.content|truncate:100:""}</div>
<div style="color:#999999;">{$comments.add_time}</div>
</td>
  </tr>
</table>
   <!--{/foreach}-->
   </div>

 



ecshop教程之首页完美调用最新评论

标签:

原文地址:http://www.cnblogs.com/yundu/p/4770760.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!