mdonders Posted August 6, 2007 Share Posted August 6, 2007 Hello. I am having a bit of problem thinking this one out and I am looking for your help. I am using a CSS template on my website and am looking to have the current page's link have a background behind it so the user knows what page they are on. I figured that if I used ['PHP_SELF'] with an if statement I could just say something to the effect of if ['PHP_SELF'] = index.php then <li class=active><a href="index.php">Home</a> and endif I for some reason cannot figure out how to put the whole code together. Your help is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/ Share on other sites More sharing options...
ViN86 Posted August 6, 2007 Share Posted August 6, 2007 are you trying to call this inside a separate CSS file, or inside the php page itself? if youre calling it from a separate CSS page, then its not going to be executed since by default, only accepted file extensions are interpreted server side. you could write a css.php page that has the CSS info, include the page on yours, then it will execute the code and echo out the CSS code (you need to be careful to have it echo at the right location). Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316710 Share on other sites More sharing options...
mdonders Posted August 6, 2007 Author Share Posted August 6, 2007 The CSS stylesheet is linked to the page so that piece of code would be in the header.php file itself. Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316712 Share on other sites More sharing options...
ViN86 Posted August 6, 2007 Share Posted August 6, 2007 so, you use header() to add the CSS info? what im really asking is, is the CSS code inside a .css file? Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316715 Share on other sites More sharing options...
mdonders Posted August 6, 2007 Author Share Posted August 6, 2007 So instead of adding <li class="active"> to all the pages make different css pages and just have those include with an if statement. The links that need to have the background are in a file called header.php and the css is in style.css Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316716 Share on other sites More sharing options...
ViN86 Posted August 6, 2007 Share Posted August 6, 2007 PHP inside a .css file will not be read with default settings. Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316722 Share on other sites More sharing options...
mdonders Posted August 6, 2007 Author Share Posted August 6, 2007 What if I made six different CSS files for each link and did: if page = index.php include styleindex.css if page = about.php include styleabout.css and in each different css file i could have the link have the background. Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316729 Share on other sites More sharing options...
mdonders Posted August 6, 2007 Author Share Posted August 6, 2007 Something like this code: <?php $currentpage = $_SERVER['PHP_SELF']; ?> <?php if ($currentpage == about.php) { include('screenabout.php'); } else { include('screen.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316743 Share on other sites More sharing options...
mdonders Posted August 6, 2007 Author Share Posted August 6, 2007 Anyone know if an if statement with multiple includes would work? I am not sure how well this would work and if thats even the correct code. Your help is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316862 Share on other sites More sharing options...
ViN86 Posted August 7, 2007 Share Posted August 7, 2007 try this... <head> <?php if ($_SERVER['PHP_SELF'] == "index.php"){ ?> <link href="styleindex.css" rel="stylesheet" type="text/css" /> <?php } else if ($_SERVER['PHP_SELF'] == "about.php"){ ?> <link href="styleabout.css" rel="stylesheet" type="text/css" /> <?php } ?> </head> this is the header for the page. Quote Link to comment https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-317501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.