ECSHOP首页调取固定的某个分类

商城的分类通常都很多,如果在网站首页全部调取,有时候会拉的很长。所以一直希望有一个可以调取固定某些分类的方法,今天终于找到了。

首先打开index.php

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

在其后面添加(这里调取了两个分类为例)

$smarty->assign('huacai', get_cat_info(8)); // 获得子分类的信息
$smarty->assign('yongtu', get_cat_info(6));

2、找到

/**
* 获得所有的友情链接
*
* @access private
* @return array
*/

在其前面添加

/**
* 获得分类的信息
*
* @param integer $cat_id
*
* @return void
*/
function get_cat_info($cat_id)
{
$res = $GLOBALS['db']->getAll('Select c.cat_id, c.cat_name, r.recommend_type FROM ' . $GLOBALS['ecs']->table('category') . ' as c LEFT JOIN ' . $GLOBALS['ecs']->table('cat_recommend') . ' as r ON c.cat_id = r.cat_id '.
" Where parent_id = '$cat_id'");
foreach ($res AS $k => $row)
{
$arr[$k]['cat_id'] = $row['cat_id'];
$arr[$k]['cat_name'] = $row['cat_name'];
$arr[$k]['recommend_type'] = $row['recommend_type'];
}
return $arr;
}

3、打开模板文件夹library,新建一个文件category_index.lbi

<!--{foreach from=$huacai item=huacai}-->
<a class="category_3tit" href="category.php?id={$huacai.cat_id}" <!--{if $huacai.recommend_type eq 3}--> class="red" <!--{/if}-->>{$huacai.cat_name}</a>|
<!--{/foreach}-->
<!--{foreach from=$yongtu item=yongtu}-->
<a class="category_3tit" href="category.php?id={$yongtu.cat_id}" <!--{if $huacai.recommend_type eq 3}--> class="red" <!--{/if}-->>{$yongtu.cat_name}</a>|
<!--{/foreach}-->

以上含义就是调取huacai代表分类id8和yongtu代表分类id6下的分类名称。

原文地址:https://www.cnblogs.com/wangblognet/p/2745883.html