首页调用最新评论

一、在根目录 打开index.php

1. 查找:  判断是否存在缓存,如果存在则调用缓存,反之读取相应内容, 看到下面有$smarty->assign这些的,如:

    $smarty->assign('invoice_list',    index_get_invoice_query());  // 发货查询
    $smarty->assign('new_articles',    index_get_new_articles());   // 最新文章
    $smarty->assign('group_buy_goods', index_get_group_buy());      // 团购商品
    $smarty->assign('auction_list',    index_get_auction());        // 拍卖活动
    $smarty->assign('shop_notice',     $_CFG['shop_notice']);       // 商店公告

在下面添加 

$smarty->assign('my_comments',     get_comments(10)); //评论添加


2、在最下面, ?> 标签前添加:

function get_comments($num)
{
   $sql = 'SELECT * FROM '. $GLOBALS['ecs']->table('comment') .
            ' WHERE status = 1 AND parent_id = 0 and comment_type=0 '.
            ' ORDER BY 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']       = $comments[$idx]['add_time']       = local_date
($GLOBALS['_CFG']['time_format'], $row['add_time']);
   $comments[$idx]['user_name']       = $row['user_name'];
   $comments[$idx]['content']       = $row['content'];
   $comments[$idx]['id_value']       = $row['id_value'];
  }
  return $comments;
}


二、打开首页模板文件 index.dwt,指定位置添加

          <div class="comments">
<!--{foreach from=$my_comments item=comments}-->
      <div class="t_l f_l"><a href="goods.php?id={$comments.id_value}" target="_blank">
{$comments.content|truncate:15:""}</a></div><div class="d_r f_r">时间:
{$comments.add_time}</div>
      <!--{/foreach}-->
  </div>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值