Jump to content

Subcategories on categories page.


brandonc503

Recommended Posts

Id like the categories.php page to show child categories of any root category*.

with:

 

Menu

Grilled

Soups

 

Drinks

Wine

Bottles

 

With category 2 as home..and Menu and Drinks in home...

on index.php?id_category=2&controller=category

 

Id like Menu to show along with its sub cats of Grilled and Soups.. same with Drinks.

 

I found this description and think its what im looking for.

 

"To display the subcategories of a category in PrestaShop, you need to create a new instance of the category class using the category's id (usually retrieved from the URL) and the language id (retrieved from cookies). After the instance has been created you can use the getSubCategories method, which take 2 parameters. The first is the language id, the second is to set whether to display only active subcategories (the default value true) or all the subcategories."

-- Feb 9th tip.. http://www.cartexpert.net/content/8-prestashop-tricks-and-tips

 

 

(* marking as root is not necessary but I figured it would allow me to check the 'root category' box to enable this script.. I could easily do without incorperating the root part if I had other way to determin which of the categories, if not all, showed subcategories)

 

thanks much.. im often in irc at

server: irc.freenode.com

channel: prestashop

Link to comment
Share on other sites

Hello brandonc503

 

I did not make this code nor have tried it out but it looks like you want the same thing as I do on my sub-category pages where i can show sub-title of that category itself is that correct? I had this made for my website and just have not had time to put in place or test it.

 

I would not try this on a live site and make sure you do a full back up please!!

 

 

<!-- Subcategories -->

<div id="subcategories">

<h3>{l s='Subcategories'}</h3>

<ul class="inline_list">

{foreach from=$subcategories item=subcategory}

<li>

<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$subcategory.name|escape:'htmlall':'UTF-8'}">

{if $subcategory.id_image}

<img src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />

{else}

<img src="{$img_cat_dir}default-medium.jpg" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />

{/if}

</a><br />

<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>

</li>

{/foreach}

</ul>

<br class="clear"/>

</div>

{/if}"

Edited by clayton29657 (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...