![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Apr 2002
Posts: 1,383
|
PHP Gurus...is there a better way?
I use PHP a lot though I am about to prove my lack of proficiency. What I am trying to do is make a single header.php and footer.php to use throughout a site...but I want to be able to use link highlighting. So, for the footer, I am trying to do this:
PHP Code:
PHP Code:
PHP Code:
Help is appreciated! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Apr 2004
Location: Toronto, ON
Posts: 1,706
|
I used pretty much the same thing in my latest project:
PHP Code:
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
It would look a little less messy if you created a function for it...
__________________
Webmasters! Looking for new affiliate programs to promote? Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ... |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
try
Code:
$links['index.php'] = 'home'; $links['how.php'] = 'how it works'; $links['about'] = 'about us blah blah'; foreach($links as $link => $textLink) echo '<a href="'.$link.'"'.(($_SERVER['REQUEST_URI']==$link)?' class="active"':'').'>'.$textLink.'</a>' |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
Incidentally, it still is a rather nasty way of doing stuff - html and php together == no no.
You really should seperate code from formatting. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
Confirmed User
Join Date: May 2002
Location: MI
Posts: 1,827
|
Quote:
Anyhow another way that can be done in a shorter syntax is: Code:
<?=($active == 'content')?'id="content":''?>
__________________
Latest MMA news. http://www.mmawrapup.com |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: May 2004
Location: South Florida
Posts: 4,134
|
I would use style sheets, and then use a SWITCH statement to turn id's off and on
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Join Date: Jul 2007
Posts: 182
|
Any examples of this? Sounds interesting.
__________________
www.adultsexzen.com - TGP www.adultsexzen.com - TRADE TRAFFIC Moniker - Your domains make you money - keep them safe! Search GFY for yourself! JaugarPC HOSTING - reliable VPS HOSTING, 30 day MONEY BACK trial, TRY RISK FREE NOW! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Too lazy to set a custom title
Join Date: Mar 2002
Location: Australia
Posts: 17,393
|
Just a quick note, REQUEST_URI always starts with a "/" . if ( $active == 'how.php' ) will never match.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Jul 2002
Location: Fort Lauderdale
Posts: 600
|
Nothing is wrong with having presentation logic in your html, as long as you don't have your business logic there. However if you want your HTML a little cleaner, you can do this with stylesheets?
<link rel="stylesheet" href="highlight-style-css.php?<?= $_REQUEST['current'] ?>" type="text/css" /> Then you have have your menu like this: <table> <tr><td><a class="menu" id="home" href="blah">Home</a></td><td><a class="menu" id="link-codes" href="blah-links">Link Codes</a></td></tr> </table> In the style sheets, you have a default for menu, and the only one you override is the one you want to show as active.
__________________
AIM: PerlScriptor |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Confirmed User
Industry Role:
Join Date: Apr 2002
Posts: 1,383
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 | |
Confirmed User
Industry Role:
Join Date: Apr 2002
Posts: 1,383
|
Quote:
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 | |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
Quote:
You don't have to repeat the array declaration. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
Confirmed User
Join Date: May 2002
Location: MI
Posts: 1,827
|
This is why I use the method I spoke about. This way its no different than a template variable. Most WYSIWYG editors can view it without any issue, and your designers will be happy. It's simple, it's clean and it works efficiently. Too maybe { }'s, foreach's, if/else statements are just going to screw with the design when it comes time for you or your designer to play with the html. Keep it simple and it will work faster and be easier to manage.
__________________
Latest MMA news. http://www.mmawrapup.com |
![]() |
![]() ![]() ![]() ![]() ![]() |