Click to See Complete Forum and Search --> : help w/link style - a:active won't work - some PHP


evo190
02-09-2009, 02:21 PM
This question has a bit of PHP included but it's mostly about the CSS style.

I have ONE page with a few links, but the links do not request a new file. It's like having only 'INDEX.html' for your entire site. Instead of going to INDEX_ABOUT.html, for 'About Us' information, I just do 'INDEX?cat=about' on the link - PHP handles the rest.

Anyway, with that in mind, I still want the links to change style for a better user experience.

Here's what I have so far:

STATIC
The first line of the page gets: <?php $thisPage="home"; ?>

LINKS
The "Home" link gets: <?php if ($thisPage=="home")
echo " id=\"currentpage\""; ?> which corresponds to a unique CSS style.

Therefore, if the "Home" link is pressed the style will be different than 'about us' or 'products'.


However, I need this to work for the other links...

HOME (a href=index?cat=home)
ABOUT US (a href=index?cat=about)
PRODUCTS (a href=index?cat=products)


So when I click "About Us" (a href=index?cat=about) there must be some way to dynamically change the STATIC line:

<?php $thisPage="home"; ?> to <?php $thisPage="about"; ?> or <?php $thisPage="producs"; ?>

I'm sure it's an echo or something. Help needed.

Fang
02-09-2009, 02:35 PM
http://www.456bereastreet.com/archive/200503/setting_the_current_menu_state_with_css/

evo190
02-09-2009, 02:43 PM
Fang, thanks for the link

The best comment from that page is below, but I'm still stumped how to make the PHP piece dynamic based on the active link.

I think a solution like this only works when the pages are static, i.e yourdomain.com/about.php(html) instead of yourdomain.com/index.php?pageid=23 - In fact, even if you’re using apache to get friendly urls, this is still possible. Wouldn’t it be easier to do something like:

<a href="theurl">thetitle</a>

Then:

if($pageid == $row[page_id]) $class = “active”;

If that’s the case, you really only need two:
nav ul li a { /* css */ } nav ul li a:hover, #nav ul li a.active {

/* declarations to style the current state */ }

Fang
02-09-2009, 02:55 PM
That is what is suggested in the link; use server side in preference to css.

criterion9
02-09-2009, 04:04 PM
http://www.webdeveloper.com/forum/showthread.php?t=201729

This is a double post.