PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
switch($page_name){
case 'index':
$i=0;
break;
case 'taf':
$i=1;
break;
case 'wwb':
$i=2;
break;
case 'hwb':
$i=3;
break;
case 'loc':
$i=4;
break;
case 'email':
$i=5;
break;
case 'jobopps':
$i=6;
break;
case 'events':
$i=7;
break;
case 'voc':
$i=8;
break;
case 'mostwanted':
$i=9;
break;
default:
$i=-1;
break;
}
$page_name is the name of the file without path or extension.
There is an array of 10 empty strings.
$i is a reference to one of the entries, which is changed to a css class of 'curPage', then i echo a large block of links and one of them has the curPage class. for example:
2-9 are for other links like for index.php and taf.php, so $classes[2] is for <a href='wwb.php' class='{$classes[2]}'>wwb</a>, and 3 is a link to hwb.php, 4 is to loc.php, etc.
Why do you have $classes and $i? It seems like all you need is $page_name and just create file and class names from the parameter value. Convention over configuration.
this is for a link bar on the side of a page, and the class curPage highlights the link on the sidebar, denoting where in the website you are. It's the same linkbar for all pages it's included in, but the actual display differs by a css class, then only depending on which page you are actually looking at. the only other option I can think of is to have css selectors like so:
Is the styling for each page link different for each page that is current? Normally what I do is create a class called 'current', then as the nav is built, I check the output of the nav (which I keep in a database) against the current page name (dirname(__FILE__)) and if it matches inside the nav loop, I assign the class 'current' to that link.
$pages=array(
'Home'=>'index',
'Tell A Friend'=>'taf',
...);
//The array continues in this fashion with the same values as in above posts
foreach($pages as $link_text => $name)
{
echo '<a href="' . $name . '_pc.php"';
echo
(($name!=$page_name) && ($name=='index'))?
' class="firstLink">':
(($name==$page_name) && ($name=='index'))?
' class="firstLink curPage">':
(($name==$page_name) && ($name!='index'))?
' class="curPage">': //this is the only condition being applied
'>';
echo $link_text . '</a>' . "\n";
}
echo '</div>';
The problem though, is that it highlights the 'index' link no matter what page I'm on, and when I look at the html source, the only class assigned to any of the links is 'curPage' to 'index'. It's not the extra lines in the conditionals is it? They're just there to look neater and help me think a little better. Basically, I just want it to give the link 'firstLink' if it's 'index' or 'firstLink curPage' if it's the index link and you're on index, or 'curPage' if your on anything else. The css dictates that firstLink gets a border all the way around and anything else in the nav bar gets a border everywhere except the top.
Any ideas on why this isn't working? I'm not coming up with anything. I'll try if statements while I wait for a reply.
hmmm...
Yeah, ok, for whatever reason, there was suddenly a directory on $page_name, but I fixed that. Now, if you're on any other page than home, it highlights both that page's link and the index link.