Jump to content

[SOLVED] How to Get All Categories Except 'Home'?


abhisek
 Share

Recommended Posts

Hello all,

How can I hide the home category? I want to display all categories, except the home category which is a root category. Since it's a root category, I can't delete it. Even if I delete, I need to make changes to child categories. Any help is appreciated.

Edited by abhisek (see edit history)

Share this post


Link to post
Share on other sites

You can check if $level_depth > 1

 

(if you have $category, use: $category->level_depth )

 

(from classes/Category.php: )

/** @var integer Parents number */
public $level_depth;
 
Root = level_depth 0
Home = level_depth 1
 
 
Hope this helps,
pascal

Share this post


Link to post
Share on other sites

Thanks, Pascal. It's of much help. However, I spent some time with classes/Category.php and there seems to be no existing function that serves the purpose. So, I made a custom sql inside a function ($id_lang is a parameter of the function OR we can use $this->context->language->id):

	$q = '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`'.Shop::addSqlRestrictionOnLang('cl').')
		'.Shop::addSqlAssociation('category', 'c').'
		WHERE cl.`id_lang` = '.(int)$id_lang.'
		AND c.`id_category` != '.Configuration::get('PS_ROOT_CATEGORY').'
		AND c.`level_depth` > 1
		GROUP BY c.id_category
		ORDER BY c.`id_category`, category_shop.`position`';
Edited by abhisek (see edit history)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More