Jump to content

Show subcategories of one category


CarlJames

Recommended Posts

Hi,

You can't do it directly from the tpl. You have to edit a module's php file, and assign the variables. If you want, you can also try to edit the categoryController, or use an override fo it.

But it any case, you'd need something like this (just an example, more stuff is needed in the query)


$current_category_id = Tools::getValue('id_category');
$subcategories = Db::getInstance()->ExecuteS('
SELECT c.id_category, cl.name, cl.link_rewrite
FROM '. _DB_PREFIX_. 'category c
LEFT JOIN  '. _DB_PREFIX_. 'category_lang cl ON (c.id_category = cl.id_category)
WHERE c.id_parent = '. (int)$current_category_id.'
');

That should do it.

Of course, you'd need to add the result to the template afterwards

 

Cheers!

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Hi,

You can't do it directly from the tpl. You have to edit a module's php file, and assign the variables. If you want, you can also try to edit the categoryController, or use an override fo it.

But it any case, you'd need something like this (just an example, more stuff is needed in the query)


$current_category_id = Tools::getValue('id_category');
$subcategories = Db::getInstance()->ExecuteS('
SELECT c.id_category, cl.name, cl.link_rewrite
FROM '. _DB_PREFIX_. 'category c
LEFT JOIN  '. _DB_PREFIX_. 'category_lang cl ON (c.id_category = cl.id_category)
WHERE c.id_parent = '. (int)$current_category_id.'
');

That should do it.

Of course, you'd need to add the result to the template afterwards

 

Cheers!

 

i have same query...:(

 

 

i need to get category(level 0th) id from subcategory (next higher level)id so how to get it can u insist me.

Link to comment
Share on other sites

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...