Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi,

I have the following menu:
Code: Select all
<ul class="project-tags">
    <cms:set my_portfolio_template_link="<cms:link 'portfolio.php' />" />
          
      
<li><h3>Categories:</h3></li>
      <li><a href="<cms:link 'portfolio.php' />" <cms:if k_template_name=='portfolio.php'>class="current"</cms:if> >All</a></li>
      <cms:pages masterpage='categories.php'>
      <li><a href="<cms:add_querystring my_portfolio_template_link "categories=<cms:show k_page_name />" />" ><cms:show k_page_title /></a></li>
      </cms:pages>
    </ul>


and I have the following problems with it:
  1. The "All" menu item is not displaying as active when on portfolio.php
  2. I'm not sure how to apply the current class to the categories

I'm not sure why the "All" isn't working, I'm probably overlooking something, but the code is the same as my main navigation menu which is working just fine.

I don't know if it's possible to add the current class to the categories, but if so I'd really appreciate the help.

Thanks!
Hi :)

The code for marking 'All' as active seems perfectly fine to me.
Is the code block you posted nested within another cms:pages block? That could change the k_template_name variable's value. Please check.

Try printing out the k_template_name value near the place you are using it to make sure it actually is coming out as 'portfolio.php'.

Once you can make it work, we can move on to your second question as it'll use the same comparison.

Coming to which, from what I could make out the link to the 'categories' page would be like:
http://www.yoursite.com/portfolio.php?categories=some_category

To mark the category being visited as active in the menu, we can use the 'categories' querystring parameter from the URL above to do a comparison. The code could be like -
Code: Select all
<cms:set my_current_category="<cms:gpc 'categories' method='get' />" />
<cms:set my_current_template=k_template_name />

<cms:pages masterpage='categories.php'>
    <cms:if my_current_template='portfolio.php' && my_current_category=k_page_name>
        <cms:set my_class='class="current"' />
    <cms:else />   
        <cms:set my_class='' />
    </cms:if>
   
    <li><a href="<cms:add_querystring my_portfolio_template_link "categories=<cms:show k_page_name />" />" <cms:show my_class /> ><cms:show k_page_title /></a></li>
</cms:pages>

Haven't actually tested the code but it should work or at least give you a pointer to the solution.

Hope it helps.
Thank you for the detailed response, will try it out later and let you know how it goes. :)
Thanks, it worked perfectly!

I realise this is an issue with the way I've done it, but is there a way to stop the "All" nav item from displaying as active when viewing one of the other categories?
4 posts Page 1 of 1