神刀安全网

ecshop调用指定分类商品到首页

第一步:找到/includes/lib_goods.php

在末尾?>前加上:

function get_cat_id_goods_index_list($cat_id = ”, $num = ”)  

//申明$cat_id,$num函数
{
$sql = ‘Select g.goods_id, g.cat_id,c.parent_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ‘ .
“IFNULL(mp.user_price, g.shop_price * ‘$_SESSION[discount]’) AS shop_price, “.
“promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, ” .
“g.is_best, g.is_new, g.is_hot, g.is_promote ” .
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘goods’) . ‘ AS g ‘ .
‘LEFT JOIN ‘ . $GLOBALS[‘ecs’]->table(‘category’) . ‘ AS c ON c.cat_id = g.cat_id ‘ .
“LEFT JOIN ” . $GLOBALS[‘ecs’]->table(‘member_price’) . ” AS mp “.
“ON mp.goods_id = g.goods_id AND mp.user_rank = ‘$_SESSION[user_rank]’ “.
“Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 “.
$sql .= ” AND (c.parent_id =” . $cat_id. ” OR g.cat_id = ” . $cat_id .” OR g.cat_id “. db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list($cat_id, 0, false))))) .”)” . “order by g.cat_id desc”;   

  //cat_id降序排列
$sql .= ” LIMIT $num”;
$res = $GLOBALS[‘db’]->getAll($sql);
$goods = array();
foreach ($res AS $idx => $row)
{
$goods[$idx][‘id’] = $row[‘article_id’];
$goods[$idx][‘id’] = $row[‘goods_id’];
$goods[$idx][‘name’] = $row[‘goods_name’];
$goods[$idx][‘brief’] = $row[‘goods_brief’];
$goods[$idx][‘brand_name’] = $row[‘brand_name’];
$goods[$idx][‘goods_style_name’] = add_style($row[‘goods_name’],$row[‘goods_name_style’]);
$goods[$idx][‘short_name’] = $GLOBALS[‘_CFG’][‘goods_name_length’] > 0 ?
sub_str($row[‘goods_name’], $GLOBALS[‘_CFG’][‘goods_name_length’]) : $row[‘goods_name’];
$goods[$idx][‘short_style_name’] = add_style($goods[$idx][‘short_name’],$row[‘goods_name_style’]);
$goods[$idx][‘market_price’] = price_format($row[‘market_price’]);
$goods[$idx][‘shop_price’] = price_format($row[‘shop_price’]);
$goods[$idx][‘thumb’] = empty($row[‘goods_thumb’]) ? $GLOBALS[‘_CFG’][‘no_picture’] : $row[‘goods_thumb’];
$goods[$idx][‘goods_img’] = empty($row[‘goods_img’]) ? $GLOBALS[‘_CFG’][‘no_picture’] : $row[‘goods_img’];
$goods[$idx][‘url’] = build_uri(‘goods’, array(‘gid’ => $row[‘goods_id’]), $row[‘goods_name’]);
}
return $goods;
}

第二部:找到index.php(根目录)

在128行$smarty->assign(‘shop_notice’,     $_CFG[‘shop_notice’]);       // 商店公告后加上:

$smarty->assign(‘cat_id1_index_goods’, get_cat_id_goods_index_list(1,8));          

//调用分类1的8个产品到首页

第三部:找到/themes/default/index.dwt

在需要调用指定分类产品的地方(依据自己的css修改)

<!–{foreach from=$cat_id1_index_goods item=goods}–>     //循环分类1产品
<a  class=”first” href=”{$goods.url}” target=”_blank”>
<img title=”{$goods.name|escape:html}” alt=”{$goods.name|escape:html}” width=”220″ height=”220″ src=”{$goods.goods_img}”/>
<p class=”title” title=”{$goods.name|escape:html}”> {$goods.name|escape:html} </p>

<p class=”price”> <span class=”label”>原价:</span><del>{$goods.market_price}</del></p>
<p class=”price qz-price”><span class=”label”>现价:</span><em>{$goods.shop_price}</em></p>
</a>
<!– { /foreach }–>   

//循环结束

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » ecshop调用指定分类商品到首页

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮