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.

Set class based on segment_3

October 03, 2007 6:12am

Subscribe [3]
  • #1 / Oct 03, 2007 6:12am

    OffLead

    12 posts

    I’m oh so close but have had no luck yet in figuring out this bit for section navigation. I need to highlight a menu item as active or not (set class=“active” to the current page location), for content items (entries) within a weblog (no categories used).

    Here is the code for the menu:

    <ul>
      {exp:weblog:entries weblog="sec_about" dynamic="off" orderby="sort_order" sort="asc"}
        <li><a href="http://{url_title_path=content/about}">{title}</a></li>
      {/exp:weblog:entries}
    </ul>

    This menu outputs the following html:

    <ul>        
      <li><a href="http://domain.com/index.php/content/about/company/">About the Company</a></li>         
      <li><a href="http://domain.com/index.php/content/about/members/">About the Members</a></li>         
      <li><a href="http://domain.com/index.php/content/about/contact/">Contact Us</a></li>         
    </ul>

    I’m assuming, perhaps incorrectly, that looking at segment_3 is the way to build a conditional statement to apply a class to the correct link. I am open to being wrong on that issue, however. 😉 I just can’t figure out exactly how to access the segment and compare it to the current location.

    I have correctly built conditionals for the main site nav that highlights the current section of the site, but can’t figure out this section navigation. The method I used for the main site navigation used a “location” variable fed to the conditional via the template used. Since all the entries here would be using the same template, that method won’t work here.

  • #2 / Oct 03, 2007 6:50pm

    e-man

    1816 posts

    This ought to do it:

    <ul>
      {exp:weblog:entries weblog="sec_about" dynamic="off" orderby="sort_order" sort="asc"}
        <li><a href="http://{url_title_path=content/about}class=active">{title}</a></li>
      {/exp:weblog:entries}
    </ul>
  • #3 / Oct 03, 2007 7:34pm

    OffLead

    12 posts

    Thanks! I was actually just heading back over here to post this very solution. After many hours of digging through various things I finally figured it out. 😊

    Now on to the next issue…haha.

  • #4 / Jan 24, 2008 9:56pm

    mrpiano

    85 posts

    Hey there,

    I’m kinda piggybacking off this post and I’m pretty close to what I want as well.

    I’m trying to get the navigation to set itself to “active” via “if” statements…

    <ul id="navlist">
    
    
     <li><a href="http://./id=current">Home</a></li>
     <li><a href="http://./aboutid=current">About</a></li>
     <li><a href="http://./servicesid=current">Services</a></li>
    
     <li><a href="http://./workid=current">See my Work</a></li>
    
     <li><a href="http://./blogid=current">Read the Blog</a></li>
    
     <li><a href="http://./contactid=current">Contact Me</a></li>
    
    </ul>

    Not sure if that’s the best code to accomplish it, so for starters, let me know.  But the issue I’m having is that my “Home” navigation only goes as far as a segment 1, so I can’t shut it off when I go to other pages because there’s ALWAYS a segment 1 of course.  I pretty much end up with 2 menu items marked as “active” at the same time.

    Any thoughts on how to “tame” the Home button?  One of the other problems I’m having is that since this header file is an {embed}, my paths seem to be exponentially getting longer…

    Thank you!

    Gino

  • #5 / Jan 24, 2008 10:37pm

    e-man

    1816 posts

    LOL.
    Not sure what you mean by exponentially longer paths but as far as your home button… how does this work for you?

    <li><a href="http://./id=current">Home</a></li>
  • #6 / Jan 24, 2008 10:40pm

    mrpiano

    85 posts

    Yes, I’m LOL, too…

    I came up with this while awaiting a reply…

    <ul id="navlist">
    
    
     <li><a href="http://{path=main/index}id=current">Home</a></li>
     <li><a href="http://{path=main/about}id=current">About</a></li>
     <li><a href="http://{path=main/services}id=current">Services</a></li>
    
     <li><a href="http://{path=main/work}id=current">See my Work</a></li>
    
     <li><a href="http://{path=main/blog}id=current">Read the Blog</a></li>
    
     <li><a href="http://{path=main/contact}id=current">Contact Me</a></li>
    
    </ul>

    Seems to be working at the moment, and so does your code, which I think adds an extra layer of logic that’ll probably pay off later.  I’m going to implement your code.

    Thanks for the immediate response!

    Gino

  • #7 / Jan 24, 2008 10:42pm

    e-man

    1816 posts

    Checking if segment_2 is empty will do the trick as well 😊
    Just having a sleepless night here, glad to be of some help!

  • #8 / Jan 24, 2008 11:18pm

    mrpiano

    85 posts

    Well, if you’re bored, may I put out a shameless request to have you take a gander at this post?  Still somewhat unresolved, but close thanks to Terry…

    Thanks!

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

ExpressionEngine News!

#eecms, #events, #releases