2011-08-15 31 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

相關問題