在PS 1.6有一个Category
类,它包含在你的控制器使用一些方便的静态方法:getCategories(...)
,getNestedCategories(...)
,getSimpleCategories
- 这些都是静态的(公共)SOU你叫他们像Category::funcName(...)
你的目的我的事情最好的办法是getNestedCategories()
它有这个头:
public static function getNestedCategories(
$root_category = null,
$id_lang = false,
$active = true,
$groups = null,
$use_shop_restriction = true,
$sql_filter = '',
$sql_sort = '',
$sql_limit = ''
)
在你的控制器,你可以这样做:
$allCategories = Category::getNestedCategories(null, $this->context->language->id);
$this->context->smarty->assign('allCategories' , $allCategories);
然后在你的模板文件类似
{foreach from=$allCategories item=mainCategory}
<div class="categoryBox">
<h2>{$mainCategory.name}</h2>
<p>{$mainCategory.description}</p>
</div>
{foreach from=$mainCategory.children item=subCategory}
<div class="categoryBox">
<h3>{$subCategory.name}</h3>
<p>{$subCategory.description}</p>
</div>
{/foreach}
{/foreach}
如果你想有家庭类的唯一的子类别,你可以使用getHomeCategories($id_lang, $active = true, $id_shop = false)
:
$allCategories = Category::getHomeCategories($this->context->language->id);
还方便的一个是静态功能getCategoryInformations($ids_category, $id_lang = null)
=>非常有用w母鸡你有你想要得到类别的某些特定ID的列表 - 你只是将它们作为阵列 - 例如用法:
$myCustomCatIDs = array(5 , 20 , 7);
$myCustomCats = Category::getCategoryInformations($myCustomCatIDs);
虽然这种联系可以回答这个问题,最好是包括的基本部分。这里的答案和提供的链接供参考。如果链接页面更改,则仅链接答案可能会失效。 – Sasa 2014-10-31 15:07:44