...

View Full Version : Need to create a function so that a image changes according to the page it is...



ndwest12
01-21-2010, 08:53 PM
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.

mlseim
01-21-2010, 09:28 PM
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?

ndwest12
01-21-2010, 09:32 PM
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.

Len Whistler
01-21-2010, 10:15 PM
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

$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
}

?>



--------------

mlseim
01-21-2010, 10:17 PM
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
// 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.


.

ndwest12
01-22-2010, 01:50 PM
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
// 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

ndwest12
01-22-2010, 06:34 PM
EDIT: Sorry for the bump, I found the solution on the WP forums



<?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

Len Whistler
01-22-2010, 06:54 PM
<?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\">";
?>

mlseim
01-22-2010, 06:59 PM
You have to have the "banner" script at the top, before you display your page.

Len Whistler
01-22-2010, 07:24 PM
--------------



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum