In my XCart 4.4.2 installation, I have a few major categories of products, each containing several subcategories. On the home page, I'd like to list the subcategories within each category but am having trouble accessing the subcategories from welcome.tpl from within this code:
{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}
Could anybody help me with the PHP/SMARTY code needed to generate lists of subcategories? Thanks!
It will be better to define an array of subcategories in php script rather than do it in template. I can provide you with the following solution for your task:
Patch for 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']) {
(lines marked with + should be added to the code)
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}