Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

How to get Selected category to the top navigation in Magento

IF you want to show Selected category to the top navigation

Go to
/app/design/frontend/default/YOURTHEMENAME/template/catalog/navigation/top.phtml

The original contents of the top.phtml file should look like below.


<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
    <ul id="nav">
        <?php echo $_menu ?>
    </ul>
</div>
<?php endif ?>

Replace the code above with this code below.


<?php $_menu = ''?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div class="nav-container">
    <ul id="nav">
    <?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php if (in_array($_category->getId(), array(10,12,15))) : ?> <?php echo $this->drawItem($_category) ?>
    <?php endif; ?>
    <?php endforeach ?>
    </ul>
</div>
<?php endif; ?>


10,12,15 is the category id which you want to display in the navigation.  

Please support us, Like us on Facebook.

0 comments:

Post a Comment

 

Copyright @ 2017 HKBlog.