• ecshop调用指定分类(包含子分类)下所有产品的评论信息


    调用指定分类(包含子分类)下所有产品的评论信息,使用了ecshop系统自带的函数get_children($cat_id)调用指定分类下所有子分类的id,该自带函数在文件include/lib_common.php文件内:

    /**
     * 获得指定分类下的商品评论
     * sun04zh3-20130321
     * @access   public
     * @param    integer $cat_id
     * @return   array
     */
    function get_comments_cat_id($cat_id)
    {
        $sql = 'SELECT c.id_value, c.user_name, c.content, c.add_time, p.goods_name, p.goods_thumb,p.goods_id  FROM '. 
                $GLOBALS['ecs']->table('comment') .' AS c '.
                ' LEFT JOIN '.$GLOBALS['ecs']->table('goods').' AS p ON p.goods_id = c.id_value '.
                ' WHERE c.comment_rank = 5 AND c.status = 1 AND c.id_value in (SELECT g.goods_id FROM '.
                $GLOBALS['ecs']->table('goods').'AS g '.'WHERE '.get_children($cat_id).') 
                ORDER BY c.comment_id DESC LIMIT 5';
        $res = $GLOBALS['db']->getAll($sql);
        $comment = array();
        foreach ($res AS $row)
        {
            $comment[] = array(
                               'id_value' => $row['id_value'],
                               'user_name'  => $row['user_name'],
                               'short_content'  => sub_str($row['content'],60),
                               'content'  => $row['content'],
                               'add_time' => date("Y-m-d H:i:s", $row['add_time']),
                               'goods_thumb' => $row['goods_thumb'],
                               'goods_short_name'  => sub_str($row['goods_name'],30),
                               'goods_name'  => $row['goods_name'],
                               'url' => build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']),);
        }
        return $comment;
    }

    category.php文件调用:

    $smarty->assign('comment',          get_comments_cat_id($cat_id));

    category.dwt文件显示:

    <!-- {foreach from=$commont item=com} -->
            <div class="pinglun-list">
                <div class="pinglun-photo">
                    <div class="pinglun-middle"><a href="{$com.url}"  title="{$com.goods_name}"><img src="{$com.goods_thumb}" width="78" height="58" border="0" /></a></div>
                </div>
                <div class="pinglun-name"><a href="{$com.url}"  title="{$com.goods_name}">{$com.goods_short_name}</a></div>
                <div class="pinglun-brief"><a href="{$com.url}" title="{$com.content}">{$com.short_content}</a></div>
            </div>
            <!--{/foreach}-->
  • 相关阅读:
    [Azure][PowerShell][ASM][03]Cloud Service
    linux ssh连接自动断开问题
    NTP服务器实现
    xshell使用小技巧
    elasticsearch集群部署
    redis集群部署
    积分排名查看
    linux centos7.2系统升级python后yum不能使用的问题
    Python生成器generator之next和send运行流程
    python文件操作
  • 原文地址:https://www.cnblogs.com/shangxia/p/2973336.html
Copyright © 2020-2023  润新知