ecshop怎么修改模板,让首页调用显示指定分类下的精品?

ecshop怎么修改模板,让首页调用显示指定分类下的精品?现在我的首页显示的是最后上传的商品。现在我重新上传商品,在首页也不显示了。请帮帮我,谢谢了。我百度也搜索了方法试... ecshop怎么修改模板,让首页调用显示指定分类下的精品?现在我的首页显示的是最后上传的商品。现在我重新上传商品,在首页也不显示了。请帮帮我,谢谢了。我百度也搜索了方法试过,不管用,如果给我解决了,我再加分,谢谢。 展开
 我来答
ecshop模板中心
2013-12-28 · TA获得超过1377个赞
知道大有可为答主
回答量:2046
采纳率:0%
帮助的人:1567万
展开全部
index.php里找到

$smarty->assign('shop_notice', $_CFG['shop_notice']); //
商店公告

在下面添加这两行代码

$children = get_children(16);//此处为产品分类ID

$this->assign( 'bestGoods16',get_category_recommend_goods('best',
$children));

第二步在调用产品的时候循环类似下面的代码

<!--{foreach from=$bestGoods16 item=goods}-->
<div class="goodsItem">
<span class="best"></span>
<a href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="goodsimg" /></a><br />
<p><a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.short_style_name}</a></p>
<font class="f1">
<!-- {if $goods.promote_price neq ""} -->
{$goods.promote_price}
<!-- {else}-->
{$goods.shop_price}
<!--{/if}-->
</font>
</div>
<!--{/foreach}-->

注意编辑PHP的时候不要用记事本,否则会导致页面出错,建议用dw软件
追问
在index.php添加了那个代码以后,首页就打不开了,显示:

Fatal error: Using $this when not in object context in /data/home/hmu155031/htdocs/index.php on line 280
追答
$smarty->assign( 'bestGoods16',get_category_recommend_goods('best', $children));

把this改成smarty应该就可以了
ecmoban模板堂
推荐于2016-02-19 · TA获得超过770个赞
知道大有可为答主
回答量:2259
采纳率:66%
帮助的人:824万
展开全部

1,打开index.php  在最上面加


/**
* 获得cat_id精品列表。
*
* @access  private
* @param   integer
* @return  array
*/
function index_get_cat_id_goods_best_list($cat_id, $num)
{
    $sql = 'Select g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price, g.promote_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 ' .
            "Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.is_best = 1 AND (" . $cat_id . " OR " . get_extension_goods($cat_id) .")";
 
$cats = get_children($cat_id);
$where = !empty($cats) ? "AND ($cats OR " . get_extension_goods($cats) . ") " : '';
$sql .=$where." 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;
}



2,$smarty->assign('auction_list',    index_get_auction());        // 拍卖活动下面加

$smarty->assign('cat_id22_best_goods', index_get_cat_id_goods_best_list(22,8));


注意这里的22是分类id,8是数量


3,模板部分


<!-- {foreach  from=$cat_id29_best_goods item=goods  name=no}-->
<div class="line">
<div class="item">
<span class="no">{$smarty.foreach.no.iteration}</span>
    <p class="pic"><a href="{$goods.url}"><img  src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="B_blue" /></a></p>
    <p class="name">  <a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.name|escape}</a></p>
    <p class="price">
    <span class="goodsPrice"> 
    <!-- {if $goods.promote_price neq ""} -->
    {$goods.promote_price}
    <!-- {else}-->
    {$goods.shop_price}
    <!--{/if}-->
    </span>
    </p>
</div>
</div>
<div style="clear:both"></div>        
<!-- {/foreach} -->
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式