I’m smart! Or not..

I’m making a new theme or layout for my fanlisting collective and I wanted those cool dynamic tabs! The ones where if you click the tab, the page shows up, and the tab is “selected” for the current page! Neat-o! It didn’t seem that difficult to do with PHP but it had its little hiccups, so to say.

At first, I tried just an if statement basically saying “if this is the current page, print ____”. So by using the $_SERVER[’PHP_SELF’] variable, I tried that. Didn’t work! It seemed logical that it would, but alas, no dynamic tabs.

At this point, I’m wondering what else I need to do to make this work. The if thing seemed logical, but didn’t work. So I looked around on google and all the PHP dynamic tabs I saw had some sort of array of the actual page names. So I tried an array. Didn’t work. But I probably did that wrong. In the end, I just wrote a function where I manually wrote in the page name for the function’s parameters and then compared it to what the server thinks is the current page.

function pagename($name) {
$currpage = basename($_SERVER[’SCRIPT_NAME’]);
$name2 = $name .”.php”;
if ($currpage == $name2) {
print ” class=\”current\”";
}
}

Yay! It works! It took me two hours to do 7 lines of code, but it works! All PHP pros out there are probably laughing at me. :\
That’s my story for the day :P

3 Comments

Leave a Comment