Log in

View Full Version : HTML question about knowing current page name..



GolfNFool_18
10-12-2006, 12:46 PM
Hello All,

Kind of new to this, so I want to see if something can be done before I spend a lot of time on something that isn't possible.

I am setting up a site that has several pages, however some pages have a central theme. Example, I have 10 pages that all have a baseball theme, while I have another 4 pages that have a basketball theme.

What I'm trying to do is call a specific header graphic, which looks different based on the theme. I have a two graphics, on that incorporates a baseball and one that uses a basketball.

I know what graphic I'd like to use based on the page name. Is there any way or value that has the page name, that an IF statement can be used to call the corect image?

Thanks,

Troy G.
http://www.crazyfangear.com

Twey
10-12-2006, 01:04 PM
This isn't an HTML question. You should use a server-side language such as PHP.

GolfNFool_18
10-12-2006, 01:19 PM
OK.. Thanks for pointing me in the right direction!!

Troy G.
http://www.crazyfangear.com

djr33
10-12-2006, 08:48 PM
It's pretty easy with PHP, but a bit more work than just html.
TOP OF YOUR PAGE:
<?php
if (strpos($_SERVER[REQUEST_URI],"baseball") !== FALSE) {
$image = "baseball";
}
?>
////INSERT YOUR HTML HERE
<img src="images/<?php echo $image; ?>.jpg">
The first part checks if "baseball" is part of the current URI (like URL) of the page. If it returns true (as in not FALSE), then $image is set to "baseball".
Later, in the image tag, the image included is set to images/$image.jpg, where image is "baseball", so it's images/baseball.jpg.

You can do other things, like you should have else {$image = "basketball";}
or something in case baseball isn't in the URI.

You could also check if ($_SERVER[REQUEST_URI] == "exacturl") {....dostuff...}
And that, if you put an address in there, be used to show you if the page was exactly "http://google.com", etc., etc.



NOTE: To use php it must be installed and enabled on your server and each page with php code must end in the extension .php. HTML, etc. will continue to work as before. You don't need to do anything special... just rename any .htm/.html/etc page to .php and it will be fine. The only difference is that <?php ... ?> commands will then be processed.
PHP is server side, so it outputs html, not the php source. It runs, then sends to the user.