Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Web Design (WordPress, Joomla, etc.) class for active page?

  • class for active page?

    Posted by Bret Williams on October 17, 2005 at 4:09 pm

    I was wondering if there’s a class for active page. For example, if the active page is the same as the link, then use a particular class.

    I know it’s been done in the past by javascript, but I was wondering if CSS can do it now.

    I’ve got a menu, and it has CSS rollover states (:hover) and I thought the :active state sounded like what I want, but it doesn’t seem to do anything. The hover state can still work, but I’d just like to change the color, letting the visitor know that’s the section they’re in.

    Thanks!

    Bret Williams replied 20 years, 7 months ago 2 Members · 7 Replies
  • 7 Replies
  • Curtis Thompson

    October 18, 2005 at 5:01 pm

    hello…

    i’m sorta following you here…i think.

    the active bit of the link is when you click on it and hold your mouse – so that brief second that it changes color it can be set (not too useful, but if you’re really into colors and presentation then you can control it – it would also be the color if you tabbed onto the link…

    there’s no good way for css to evaluate what page it’s on and show a style accordingly. what i often do is make a copy of my link style and add “On” to the style name and then (if it’s php, etc. header), do the old if script name == page url then also echo “On” to the css class – then the right style is called for that page and it shows as on…

    is that what you were thinking of? sounds like you already knew how to do it, though…

    sitruc

  • Bret Williams

    October 18, 2005 at 6:35 pm

    Darn. Was hoping I was missing something. Good info on active. Yeah, useless. I uually call that the “down” state so I didn’t pick up on “active” meaning that.

    On the JS, I know how it’s done, but haven’t been able to find a simple script for it. Is there a simple line of javascript that can be added to each menu item? I can handle adding the CSS no problem.

    Specifically, the site I’m working on… hownet.lunarpages.net/retail

    The menus on the left do what you’re describing, but I don’t know enough javascript to decipher how they do it. It’s a DW script extension. I can of course change their CSS styles.

    I can use the same extension to create horizontal menus, but I don’t need the pull downs, and I’ve already got the CSS how I want it, etc.

  • Curtis Thompson

    October 18, 2005 at 7:05 pm

    hello…

    i’d do something like this:

    not on that page:

    <div><a class=”navLink” href=”/retail/cretailsalesskills.php”>Retail Sales Skills</a></div>

    on that page:

    <div><a class=”navLinkOn” href=”/retail/cretailsalesskills.php”>Retail Sales Skills</a></div>

    so then the trick becomes updating that with php to show the “On” if you’re on that page…so something like this should work:

    <div><a class=”navLink<?= ($_SERVER[‘SCRIPT_NAME’] == “/retail/cretailsalesskills.php”)) ? “On” : “” ?>” href=”/retail/cretailsalesskills.php”>Retail Sales Skills</a></div>

    thoughts?

    sitruc

  • Bret Williams

    October 19, 2005 at 2:21 am

    Well, I don’t speak PHP but I can understand it I think. But I think my issue might be more complex than your example. I’m looking for a way to highlight the horizontal main menu links. So it has to look for a particular directory, not a specific page. To use the retail page as an example, the link is simply /retail. Which takes you to index.php. But I want it highlighted for all the pages in the retail section.

    The links on the left already have this function because of the extension I purchased which creates the twirl down menus.

    In the example you give, it seems that this is how it works… (the class I use is “biglinks”)

    class=”biglinks(then you insert the script here that says if the current page is so and so then print “ON,” otherwise, then print “” (nothing). That I understand. The script is filling in the end of the class with either ON or nothing, which will determine it’s appearance. Exactly what I looking to do. What I don’t understand is the $_SERVER[‘SCRIPT_NAME’] part. Is that a built in function, or am I to call on a script that will determine the page or directory I’m viewing?

  • Curtis Thompson

    October 19, 2005 at 2:32 am

    hello…

    [Bret Williams] “s that a built in function, or am I to call on a script that will determine the page or directory I’m viewing?”

    the $_SERVER array is a built-in array in php that has a wide variety of useful parameters. you could figure out the directory by using that same script name param and the php dirname function (https://us2.php.net/dirname)…

    you can find some other useful vars by making a dummy file and putting the php info at the top:

    <?= phpinfo() ?>

    you’ll see all the params (and a bunch of other stuff) that php knows about each script. you can try putting the script in different dirs (say you do the above and save it as phpinfo.php) to see how the variables change…

    make sense?

    sitruc

  • Bret Williams

    October 19, 2005 at 4:04 am

    Well, I have no idea what you’re talking about. But I made it happen somehow anyway. Great little piece of code to add to the arsenal.

    You had an extra closing parenthesis, and I had to figure out how to add parentheses when I added he dirname in front of what you had. The link to the php manual helped me get it.

    I think. 🙂

    Thanks!

  • Bret Williams

    October 19, 2005 at 4:50 am

    Whoops posted that last reply to the wrong post. Anyway. Got it. It’s all functional.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy