NOTE: The categories are not the categories which are related to product those categories are and extension categories like for example this categories belong to blog and there are some items under this categories.

I have some categories which are fetched dynamically in this way

<li><a href="<?php echo $cat->getAddress(); ?>" ><?php echo $cat->getTitle(); ?></a></li>

Now if a category is selected I want to show it highlighted in this way means it should be shown as in active stage. enter image description here

so far I tried giving class="current" to <li> and by writing CSS for that but that doesn't worked please help me in solving this thanks in advance.

Please someone look into this issue.

4 Answers 4


Assuming the categories fetched dynamically using foreach loop.

<?php foreach ($cats as $cat): ?>
   <?php $cat_u = $cat->getAddress(); ?>
   <?php $cur_u = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>
   <li class="<?php if($cat_u == $cur_u) echo "active" ?>"><a href="<?php echo $cat->getAddress(); ?>" ><?php echo $cat->getTitle(); ?></a></li>
<?php endforeach; ?>

<?php $cat_u = $cat->getAddress(); ?>-->This thing gets the address of your categories

<?php $cur_u = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>-->This will fetch your present pages URI.

and <li class="<?php if($cat_u == $cur_u) echo "active" ?>">

if categories address=Current uri then that <li> class will be active.

Hope this works for you


I think you can check it by:

<li<?php echo in_array($cat->getId(), Mage::registry('current_category')->getPathIds()) ? ' class="current"' : '' ?>>

Hope it helps, good luck! ;)

  • thanks for the answer but this thing crashing my page
    – Abdul
    Dec 17, 2014 at 8:54
  • can you check if you have "Mage::registry('current_category') initialized ? If you do, try to replace ->getPathIds() with getId().
    – dsitovs
    Dec 17, 2014 at 10:04

Add Following Jquery code to your navigation file.

$j(function() {
  $j('.list-group a[href^="/' + location.pathname.split("/")[2] + '"]').addClass('current');

In 3rd line of above code just change .list-group to your class(class of navigation division.)

Good Luck!!!

  • Doesn't make any sense anyway thanks for the answer
    – Abdul
    Dec 17, 2014 at 9:06

You can try with below code. It's works for me.

<?php $current_cat = Mage::registry('current_category'); $selectclass = ($current_cat->getId() == $cat->getId())?' class="current"':'' ?> <li<?php echo $selectclass;?>><a href="<?php echo $cat->getAddress(); ?>" ><?php echo $cat->getTitle(); ?></a></li>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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