2011-08-15 34 views
0

在我的XCart 4.4.2安装中,我有几个主要类别的产品,每个产品都包含几个子类别。在主页上,我想列出每个类别中的子类别,但我在访问从welcome.tpl子类别从该代码中的麻烦:任何人可以帮助我的PHP /所需在XCart中,如何列出类别中的子类别?

{foreach from=$categories_menu_list item=c name=categories} 
    <a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}"> 
    <li> 
     <img src="{$c.image_path|amp}" alt="{$c.category|escape}"/> 
     <strong>{$c.category}</strong><br/> 

     <!-- list subcategories here--> 
     {php} 
      $parentid = $c.categoryid; 

      $categoryNames = func_query_column("SELECT category FROM $sql_tbl[categories] WHERE parentid = " . $parentid); 
      print_r($categoryNames); 
     {/php} 
    </li> 
    </a> 
{/foreach} 

SMARTY代码生成子类别列表?谢谢!

+0

我只是想出了PHP可以,我也许可以使用要做到这一点,但它不工作(2原因:parentid值设置不正确,并且SQL查询总是返回一个空集)。有任何想法吗?请帮忙!! – Vivek

回答

2

最好是在php脚本中定义一个子类别的数组,而不是在模板中。我可以为您提供您的任务如下解决方案:

修补程序包括/的common.php

@@ -90,6 +90,14 @@ 
     // Get categories menu data 
     if (!empty($categories)) { 
      $smarty->assign('categories_menu_list', $categories); 
+ 
+   if (!isset($cat) || 0 == intval($cat)) { 
+    $extended_categories = func_get_categories_list(0, true, true, 1); 
+ 
+    if (!empty($extended_categories)) { 
+     $smarty->assign('extended_categories_list', $extended_categories); 
+    } 
+   } 
     } 

     if ($active_modules['Manufacturers']) { 

(行标有+应该添加到代码)

皮肤/your-skin/customer/main/welcome.tpl

{foreach from=$categories_menu_list item=c} 
<a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}"> 
    <li> 
    <img src="{$c.image_path|amp}" alt="{$c.category|escape}"/> 
      <strong>{$c.category}</strong><br/> 
    <!-- list subcategories here--> 
    {foreach from=$extended_categories_list item=ec} 
     {if $ec.parentid eq $c.categoryid}{$ec.category|escape}<br />{/if} 
    {/foreach} 
    </li> 
</a> 
{/foreach} 
1

经典的回答也不太工作FO我。以下是我使用的:

// Get categories menu data 
    if (!empty($categories)) { 
     $smarty->assign('categories_menu_list', $categories); 

     foreach($categories as $c){ 
      $ext_cats = func_get_categories_list($c['categoryid'], true, true, 1); 
      if(!empty($ext_cats)){ 
       $extended_categories[$c['categoryid']] = $ext_cats; 
      } 
      $ext_cats = ""; 
     } 

     if (!empty($extended_categories)) { 
      $smarty->assign('extended_categories_list', $extended_categories); 
     } 
    } 

这循环遍历每个类别并获取所有子类别。

0

我知道这是一个古老的线程,但经典的代码对我很好,只是稍作修改(使子类链接)。 我能做些什么来获得3级+子类别(子子类别)?

抱歉发布在错误的地方。为了弥补它,我确实有一个经典代码的补充。原代码刚刚上市的子类别文字/图片,下面是我用什么来摆脱的图片,但是让子类可点击的链接

<ul> 
    {foreach from=$categories_menu_list item=c} 
    <li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}"><strong>{$c.category}</strong></a></li> 

    <!-- list subcategories here--> 
    {foreach from=$extended_categories_list item=ec} 
    {if $ec.parentid eq $c.categoryid}<li><a href="home.php?cat={$ec.categoryid}" style="font-size:10px;">{$ec.category|escape}</a></li>{/if} 
    {/foreach} 

    {/foreach} 
    </ul> 
+0

如果您有新问题,请随时提问,而不是发布答案。 – empiric

相关问题