FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

Nav - how to recognize "current"?

Feed 16 posts, 5 voices

Avatar
1493 posts

I have this CSS in my Styles.css file:

nav li a:hover { background: #3C6787; color: #fff; }

nav li a.current { background: #fd9; color: #000; }

But the Header snippet does not seem to have any code to recognize "current". It looks like the current Frog site has this working. What do I need to do to get this behaviour in 2.2? Thanks!

David.

 
Avatar
541 posts

humm this is because I have hardcoded the menu. but you can check with url_match('url_of_the_page') or url_start_with('start_of_your_url')

 
Avatar
7 posts

In the site I'm building I have a main menu and one sub menu.

so to have a .selected on my menus I used this:

if(in_array($menu->slug, explode('/', $this->url))) { $class = "selected "; }else{ $class = NULL; }

haven't tried url_match() or url_start_with()

 
Avatar
541 posts

ha cool ! I haven't think that way!! if it works it's perfect :)

 
Avatar
1493 posts

Thanks for this, Nicolas. I tried to implement your code in various ways in the "header" snippet. I inserted it at various points here, and added a "dynamic" class= in the

  • tag. The whole snippet code looks like this (of course!):

    • home
    • <?php $home = $this->find('/'); $home_childs = $home->children(); foreach($home_childs as $menu): ?>
    • <?php $menu->link(); ?>
    • <?php endforeach; ?>

    Would be willing to share how you're using your "if" statement more fully? Thanks! David.

  •  
    Avatar
    1493 posts

    Ack! My markup went wrong in post #5 -- sorry about that! Hope it's still clear....

     
    Avatar
    1493 posts

    And one more thing (sorry!): if the "class" needs to be set on the "anchor" tag, not the "list" tag, how do you get that, because the menu links are generated like this:

    <li><?php $menu->link(); ?></li>

    (I hope I've entered that correctly this time!) I have looked in the Frog directories for where the "$menu" gets created, but can't find it (or maybe I'm looking in the wrong place!). Thanks again. David.

     
    Avatar
    7 posts

    Hi david, here's an example.

     
    Avatar
    541 posts

    end what about this one:

    <ul> 
        <?php foreach($this->find('/')->children() as $menu): ?>
        <li><?php $menu->link($menu->title, (in_array($menu->slug, explode('/', $this->url)) ? 'selected': null)) ?></li>
        <?php endforeach; ?> 
    </ul>
    
     
    Avatar
    1493 posts

    Not just one, but TWO examples, and BOTH work!! MERCI BEAUCOUP Nicolas et Philippe!

    I wanted to include the "Home" tab at the beginning of my nav. Using the code that Nicolas provided, I came up with this:

    <?php if($_SERVER['REQUEST_URI'] == "/frog/") //Substitute base directory as last element { $homeclass = "current"; } else { $homeclass = NULL; }
    if (!empty($homeclass)) { $homeclass = 'class="'.$homeclass.'"';
    } ?> <li><a href="<?php echo BASE_URL; ?>/" <?php echo $homeclass ?>>Home</a></li>

    I hope I have I entered that correctly. If I didn't, I will post a link to a text file.

    This is really, really great! Thanks for all the help!

    David.

     
    Avatar
    1493 posts

    Well, my "code-block" didn't quite work! :( But if you make the line-breaks like Nicolas's example, it should work. (And I used "current" in my example rather than "selected".)

    David.

     
    Avatar
    541 posts

    and what about this one :

    <li><a<?php echo url_match('/') ? ' class="current"': ''; ?> href="<?php echo BASE_URL; ?>">home</a></li>
    
     
    Avatar
    1493 posts
    and what about this one :

    Magnifique! :)

     
    Avatar
    44 posts

    Hello Dear,
    my name is peace i saw your profile and i
    found
    pleasure
    to write you as my my friend so that we can communicate to each
    othere,please mail me through my email address
    (peacelove_khalifa@yahoo.com )
    that i will send you my pic for you to know who i am for the love and
    pleasure i have develpoed in your lovely profile i awaits your lovely
    reply
    as soon as you get this mail.
    peace
    please please please contact this email directly
    peacelove_khalifa@yahoo.com

     
    Avatar
    1 posts

    Thanks for kicking off the replies and your thoughts.
    Amul Kapoor