ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Newbie question: is it possible to add a specific css class to the menu link of the current page?

January 18, 2011 7:11am

Subscribe [3]
  • #1 / Jan 18, 2011 7:11am

    martinj

    32 posts

    Hi everyone

    I have a real newbie question here but I can’t find an answer in the forums - I’m also not yet sure of the correct EE terminology so apologies if I use the wrong name for something…

    I’m building my first EE2 site (using Building Websites with ExpressionEngine2 by Leonard Murphy as a guide). I want EE to output the main navigation as an unordered list which will be styled using css. I also want EE to add a unique id or class to the list item relating to the current page so that it can be highlighted, again using css. For example:

    <ul class="menu-navigation">
    <li>Home</li>
    <li>About the Project</li>
    <li>Choose a Walk Near You</li>
    <li class="current-page">Local Maps</li>
    <li>Activities</li>
    <li>Contact</li>
    </ul>

    I don’t know if this is possible to do with a standard EE2 install or if I need an extension? I’ve seen the NavEE module which looks like overkill for what I want. Does anyone have any other ideas?

    Thanks

  • #2 / Jan 18, 2011 9:15am

    Focus Lab Dev Team

    1129 posts

    Hi Martin. Welcome 😊

    One common approach is to use segment conditionals to see what page you’re on. For example, if your “Local Maps” page is located at http://yoursite.com/local-maps/ you could do something like this:

    <li{if segment_1 == 'local-maps'} class="current-page"{/if}>Local Maps</li>

    Does that make sense? Would that be doable in your particular site?

  • #3 / Jan 18, 2011 9:24am

    martinj

    32 posts

    Hi Erik

    Thanks for your help. Yes, I think that might work. In researching this I’ve found that navigation menus in EE are much more flexible but also more complicated than in most CMSs. I’ll have to research the whole issue some more - but your solution will definitely work if I choose to use hard coded navigation for the main sections. I may look at NavEE, Structure or similar for dynamic navigation within each section of the site.

    Thanks again.

  • #4 / Jan 18, 2011 9:27am

    Focus Lab Dev Team

    1129 posts

    Glad to help. Also take a look at Taxonomy as a free alternative (and a great alternative as well)

  • #5 / Jan 18, 2011 9:32am

    martinj

    32 posts

    OK, will do.

  • #6 / Jan 18, 2011 9:55am

    Boyink!

    5011 posts

    but your solution will definitely work if I choose to use hard coded navigation for the main sections.

    This has always been my recommendation anyway.  No sense running queries day in and day out to build something dynamically that rarely, if ever, changes - and when it does will likely require other development work.

    Fix the main nav, then make it dynamic from there.

  • #7 / Jan 18, 2011 10:13am

    martinj

    32 posts

    Thanks Boyink!

    I found a blog entry discussing EE navigation earlier this morning - plenty of comments including some from you I believe. Many suggested static navigation for main site sections and I follow the reasoning behind it. I had not thought of using hard coding before reading it but the blog gave me the idea. EE appears very flexible and with that comes the need for education 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases