Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Adding Subcategories on Home page

   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
Thread Tools Search this Thread
Old 12-12-2019, 11:08 PM
siddharth.puri@wheelandba siddharth.puri@wheelandba is offline

Advanced Member
Join Date: Nov 2019
Posts: 66

Question Adding Subcategories on Home page

Hi i want to add sub categories on home page. I have a category Promotions which has sub categories.

How can I add sub categories of this category on the home page.

{% if this.getSubcategories() %}
<div class="subcategories-container overide">
<div class="subcategory-heading">
<span class="category-name">{{ t('Subcategories') }}</span>
<ul class="subcategory-view-icons subcategory-list grid-list clearfix">
{% for subcategory in this.getSubcategories() %}
{% if subcategory.hasAvailableMembership() %}
<a href="{{ url('category', '', {'category_id': subcategory.category_id}) }}">
<span class="subcategory-icon" style="width:100%; height:100%;">
{{ widget('\\XLite\\View\\Image', image=subcategory.image, maxWidth=this.getIconWidth(), maxHeight=this.getIconHeight(), centerImage='1', alt=this.getAlt(subcategory.image)) }}
<span class="subcategory-name" style=" width:100%; font-size: 18px !important; font-weight:bold;">{{ }}</span>
{% endif %}
{% endfor %}
{% for item in this.getNestedViewList('children') %}
<li>{{ item.display() }}</li>
{% endfor %}
{% endif %}
{{ widget_list('subcategories.base') }}


Below this I want to display the sub categories of one of these categories.

I can catch that specific category by using subcategory.category_id == 10

Now I am struggling to display its sub categories

- X-Cart Version
Reply With Quote
Old 07-05-2020, 05:23 AM
Ed B. Ed B. is offline

Join Date: Apr 2016
Posts: 401

Default Re: Adding Subcategories on Home page

  • Probably there is a way to find the set of all subcategories from the category. Basically if you get the properties of a category, you will get these, and from which you will find a way to loop over them.
  • This might be less elegant, but the relation "the category with id n is a subcategory of the category with id m" is stored in the xc_categories table in the entry for the category id m, the value n in the column "root category". So instead of looking for all subcategories of the category m, you can simply look for all categories whose root category is m, and you are done.
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote

The following user thanks Ed B. for this useful post:
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -8. The time now is 06:38 AM.


X-Cart forums © 2001-2020