cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide the category which is not belong in the same product.

How to hide the category which is not belong in the same product.

Hi Everybody,

I'm quite new with magento and I can't find solution with this problem:

I would like to hide the categoies which are not belong in the same products.

Please see the printscreens for easy understanding.

1. Front Office

Please visit the link below to see the printscreen picture.

http://www.mx7.com/view2/zukesk2kpTlwqMy3

 

2. Back Office

Please visit the link below to see the printscreen picture.

http://www.mx7.com/view2/zukhbLSjXtM0uv5O

 

Looking forward to hear from you guys,

Cheers,

 

 

2 REPLIES 2

Re: How to hide the category which is not belong in the same product.

Hi @armzzplayboy, your image links don't seem to work. Maybe post them here instead?

 

Unfortunately, I'm not sure what you're asking so it's difficult to answer without the visuals.

--

Developer Relations, Adobe Experience Cloud
Problem solved? Click Accept as Solution!
Still stuck? Check out our documentation: https://magento.com/resources/technical

Re: How to hide the category which is not belong in the same product.

See if below code help you to get what you want.

 

Let's say that you already have the current category in the variable $category. This piece of code should give you all the (active) category siblings.

$siblings = Mage::getModel('catalog/category')->getCollection()->setStoreId(Mage::app()->getStore()->getId());
$siblings->addAttributeToSelect('*')
        ->addAttributeToFilter('parent_id', $category->getParentId()) //siblings have the same parent as the current category
        ->addAttributeToFilter('is_active', 1)//get only active categories
        ->addAttributeToFilter('entity_id', array('neq'=>$category->getId()))//exclude current category
        ->addAttributeToSort('position');//sort by position

Now you can use loop of the siblings and list them:

<?php foreach ($siblings as $sibling): ?>
    <a href="<?php echo $sibling->getUrl();?>"><?php echo $sibling->getName();?></a><br />
<?php endforeach;?>

References: http://magento.stackexchange.com/questions/1303/how-to-show-category-siblings

Thanks