Results 1 to 4 of 4

Thread: HTML question about knowing current page name..

  1. #1
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HTML question about knowing current page name..

    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This isn't an HTML question. You should use a server-side language such as PHP.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK.. Thanks for pointing me in the right direction!!

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

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It's pretty easy with PHP, but a bit more work than just html.
    PHP Code:
    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •