Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Need to create a function so that a image changes according to the page it is...

    Hi,

    I have a snippet of code that I'm going to try but I was hoping you guys might be able to point me in an easier direction.

    I'm working on a wordpress site, and I need an image on certain pages to change according to what page it is.

    For example:
    http://www.sebuilding.com/retail-shopnow

    has a different flash video in the header compared to

    http://www.sebuilding.com/contractors-shopnow

    That is a php site based in magento.

    hopefully my desciption is good enough, its kinda hard to explain it. But I know that that works but looking at the end slug of the url and replacing the flash video accoridingly.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Do you have a site to show us? (your wordpress site)?

    Somehow, the script would need to figure-out what page it was on,
    and there are different WP ways to do the URL's. I think that will be
    the hardest part ... and how many different headers for how many pages?

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    Do you have a site to show us? (your wordpress site)?

    Somehow, the script would need to figure-out what page it was on,
    and there are different WP ways to do the URL's. I think that will be
    the hardest part ... and how many different headers for how many pages?
    The site i'm working on is www.tkgwebdesign.com

    I have the slugs working correctly unless a problem was to run in with the redirector i have running and or the removal of the blog slug. (both plugins on the WP) The image would go inside the empty area at the top. The image will eventually turn to a flash movie when i create that, but i really want to get down the recognizer before that.

    So in regards to the site, the portfolio section would be different than the services section and so on.

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    WP can be tricky to customize but something like the code below should work. It's untested and would need some tweaking.


    Install in the header file, such as header.php
    PHP Code:
    <?php

    $page_name 
    basename($_SERVER['REQUEST_URI']);

    if (
    $page_name == services) {
    // Display services banner
    }

    if (
    $page_name == portfolio) {
    // Display portfolio banner
    }

    if (
    $page_name == news) {
    // Display news banner
    }

    ?>


    --------------
    Leonard Whistler

  • Users who have thanked Len Whistler for this post:

    ndwest12 (01-22-2010)

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Here's my idea for this ...

    You're looking for two different words to be in the URL -- "/gallery" and "/services".

    So, in the WP script/template that displays the "body", before it displays the banner,
    insert a small script like this that looks at the current URL and determines which one
    it is ... and then pick the correct banner.

    PHP Code:
    <?php
    // Grab the current URL.
    $url $_SERVER["SCRIPT_NAME"];

    // The default banner
    $banner "mysite.com/themes/images/banner1.jpg";

    if(
    stristr($url,"gallery")){
    $banner "mysite.com/themes/images/gallery_banner.jpg";
    }
    if(
    stristr($url,"services")){
    $banner "mysite.com/themes/images/services_banner.jpg";
    }

    // then use $banner in your code for the banner part.
    // it could be .jpg or .flv or .swf  (whatever).

    ?>
    Len ... JINX! We posted at the same time.


    .

  • Users who have thanked mlseim for this post:

    ndwest12 (01-22-2010)

  • #6
    New Coder
    Join Date
    Sep 2009
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    Here's my idea for this ...

    You're looking for two different words to be in the URL -- "/gallery" and "/services".

    So, in the WP script/template that displays the "body", before it displays the banner,
    insert a small script like this that looks at the current URL and determines which one
    it is ... and then pick the correct banner.

    PHP Code:
    <?php
    // Grab the current URL.
    $url $_SERVER["SCRIPT_NAME"];

    // The default banner
    $banner "mysite.com/themes/images/banner1.jpg";

    if(
    stristr($url,"gallery")){
    $banner "mysite.com/themes/images/gallery_banner.jpg";
    }
    if(
    stristr($url,"services")){
    $banner "mysite.com/themes/images/services_banner.jpg";
    }

    // then use $banner in your code for the banner part.
    // it could be .jpg or .flv or .swf  (whatever).

    ?>
    Len ... JINX! We posted at the same time.


    .
    thanks guys, this actually looks like the code I have right now but your advice has definately helped, I'll update you when I get it to work

  • #7
    New Coder
    Join Date
    Sep 2009
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts
    EDIT: Sorry for the bump, I found the solution on the WP forums

    PHP Code:
    <?php

    if(is_page('Services')){
    echo 
    '<img src="http://tkgwebdesign.com/wp-content/uploads/2010/01/blue.gif" />';
    }

    if(
    is_page('About Us')){
    echo 
    '<img src="http://tkgwebdesign.com/wp-content/uploads/2010/01/green.gif" />';
    }

    if(
    is_page('Portfolio')){
    echo 
    '<img src="http://tkgwebdesign.com/wp-content/uploads/2010/01/yellow.gif" />';
    }

    if(
    is_page('Request a Quote')){
    echo 
    '<img src="http://tkgwebdesign.com/wp-content/uploads/2010/01/blue.gif" />';
    }

    ?>
    this code works to add different headers into different pages by their title
    Last edited by ndwest12; 01-22-2010 at 07:13 PM. Reason: solved

  • #8
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    PHP Code:
    <?php
    // Grab the current URL.
    $url $_SERVER["SCRIPT_URI"];

    // The default banner
    $banner "gallery.gif";

    if(
    stristr($url,"gallery")){
    $banner "gallery.gif";
    }
    if(
    stristr($url,"services")){
    $banner "services.gif";
    }

    echo 
    "<img src=\"tkgwebdesign.com/images/$banner\">";
    ?>
    Leonard Whistler

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    You have to have the "banner" script at the top, before you display your page.

  • #10
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    --------------
    Last edited by Len Whistler; 01-22-2010 at 07:28 PM. Reason: Wrong Information
    Leonard Whistler


  •  

    Posting Permissions

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