0

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; ?>
1

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>
  • Thank you MTM. I used your code and changed a few things, so it fits my needs. If you are interested, you can see my final code below. – McKeene Aug 19 '14 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.