Question

For SEO reason I would like to display both the name of the parent category and the sub-category in the headline of a catalog page, but only in some cases. I don't want to use it in the original parent categories because it then will display "default category" in front of the category name, so it would display "Default category Ralph Lauren".

If the category ID is 2, 3, 4, 5, 6, 7 and 43 i would like to echo;

<div class="headingBox">
    <?php if($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
        <a href="<?php echo $this->getRssLink() ?>" class="link-rss"><?php echo $this->__('Subscribe to RSS Feed') ?></a>
    <?php endif; ?>
    <h2 class="line_heading"><span> <?php $parentname = $this->getCurrentCategory()->getParentCategory()->getName(); echo $parentname; ?> 
<?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></span></h2>
</div>

But on any other category page I would like to echo;

<div class="headingBox">
    <?php if($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
        <a href="<?php echo $this->getRssLink() ?>" class="link-rss"><?php echo $this->__('Subscribe to RSS Feed') ?></a>
    <?php endif; ?>
    <h2 class="line_heading"><span> 
<?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></span></h2>
</div>

I've tried using the following snippet on one of the categories, but it just display two headings;

<?php if (Mage::registry('current_category') == 2): ?>
// display content for category with the ID 2
<?php else: ?>
// content for other categories
<?php endif; ?>
Was it helpful?

Solution

you can update the code as

<div class="headingBox">
    <?php if($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
         <a href="<?php echo $this->getRssLink() ?>" class="link-rss"><?php echo $this->__('Subscribe to RSS Feed') ?></a>
    <?php endif; ?>
    <?php $showparentfor = array(2,3,4,5,6,7,43);
          if(in_array($_category->getId(),$showparentfor )):
     ?>
        <h2 class="line_heading"><span>
    <?php $parentname = $this->getCurrentCategory()->getParentCategory()->getName();
          echo $parentname; ?>
         </span></h2>
    <?php else: ?>
         <h2 class="line_heading"><span> 
    <?php endif; ?>
    <?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?>
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top