ecshop获取点击人气排行榜

2016-09-07 22:03 来源:www.chinab4c.com 作者:ecshop专家

ecshop获取点击人气排行榜

两部分。index.php和lib_goods.php
关于涉及到index.dwt的,请将按销量排行的改为from = top_hots_all
 

index.php增加

$smarty->assign('top_hots_all',       get_top10_hot(0));           // 全部人气排行

 

/**

lib_goods.php lib库增加函数(children取得子类产品id)
* 调用当前人气排行榜
*按点击排列 i<10 显示10个
* @access  public
* @param   string  $cats   查询的分类
* @return  array
*/

function get_top10_hot($cats)
{
if (empty($cats))
{
  $children = '';
}
   else
{
    $children =  "WHERE ".get_children($cats);
}
  $sql = 'SELECT * ' .
            ' FROM ' . $GLOBALS['ecs']->table('goods') .' g '.
            "  $children" .
            ' ORDER BY click_count DESC LIMIT 0 , 10';

    $hot = $GLOBALS['db']->getALL($sql);

    for ($i = 0; $i < 10; $i++)
    {
        $hot[$i]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
                                    sub_str($hot[$i]['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $hot[$i]['goods_name'];/*$hot[$i]['goods_name'];*/
        $hot[$i]['url']        = build_uri('goods', array('gid' => $hot[$i]['goods_id']), $hot[$i]['goods_name']);
  $hot[$i]['name'] = $hot[$i]['goods_name'];

    }
    return $hot;
}

(责任编辑:chinab4c)