Php 在XCart中,如何列出类别中的子类别?

Php 在XCart中,如何列出类别中的子类别?,php,smarty,x-cart,Php,Smarty,X Cart,在我的XCart 4.4.2安装中,我有几个主要的产品类别,每个类别包含几个子类别。在主页上,我想列出每个类别中的子类别,但从以下代码中访问welcome.tpl中的子类别时遇到问题: {foreach from=$categories_menu_list item=c name=categories} <a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}"> <li>

在我的XCart 4.4.2安装中,我有几个主要的产品类别,每个类别包含几个子类别。在主页上,我想列出每个类别中的子类别,但从以下代码中访问welcome.tpl中的子类别时遇到问题:

{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}
{foreach from=$categories\u menu\u list item=c name=categories}
{/foreach}

有人能帮我生成子类别列表所需的PHP/SMARTY代码吗?谢谢

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

include/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']) {
(标有+的行应添加到代码中)

skin/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}
{foreach from=$categories\u menu\u list item=c}
{/foreach}

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

include/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']) {
(标有+的行应添加到代码中)

skin/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}
{foreach from=$categories\u menu\u list item=c}
{/foreach}

经典答案对我来说不太合适。以下是我使用的:

    // 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);
        }   
    }

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

经典答案对我来说不太合适。以下是我使用的:

    // 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);
        }   
    }

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

我知道这是一个旧线程,但classic的代码对我来说非常有用,只需稍加修改(使子类别链接)。 我该怎么做才能让3级以上的子类别(子类别)也显示出来

为在错误的位置发布而道歉。为了弥补这一点,我确实在classic的代码中添加了一个。原始代码只是以文本/图像的形式列出了子类别,下面是我用来去除图片的内容,但是让子类别单击可链接

    <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>
    {foreach from=$categories\u menu\u list item=c}
  • {foreach from=$extended_categories_list item=ec} {if$ec.parentid eq$c.categoryid}
  • {/if} {/foreach} {/foreach}

我知道这是一个旧的线程,但classic的代码对我来说非常有用,只做了一些轻微的修改(使子类别链接)。 我该怎么做才能让3级以上的子类别(子类别)也显示出来

为在错误的位置发布而道歉。为了弥补这一点,我确实在classic的代码中添加了一个。原始代码只是以文本/图像的形式列出了子类别,下面是我用来去除图片的内容,但是让子类别单击可链接

    <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>
    {foreach from=$categories\u menu\u list item=c}
  • {foreach from=$extended_categories_list item=ec} {if$ec.parentid eq$c.categoryid}
  • {/if} {/foreach} {/foreach}

我刚刚发现PHP可以用来实现这一点,但它不起作用(两个原因:parentid值设置不正确,SQL查询总是返回空集)。有什么想法吗?请帮忙!!我刚刚发现PHP可以用来实现这一点,但它不起作用(两个原因:parentid值设置不正确,SQL查询总是返回空集)。有什么想法吗?请帮忙!!如果你有新问题,请随意提问,而不是发布答案。如果你有新问题,请随意提问,而不是发布答案。