PHP newbie needs help...
- Started
- Last post
- 6 Responses
- Sep
I'm working with this snippet of code:
<?php if (is_home()) { ?>
<img src="<?php bloginfo('template_url'); ?>/img/pic-sidebar0.gif" width="200" name="MyImage"/>
<?php } elseif (is_page('48')) { ?>
<img src="<?php bloginfo('template_url'); ?>/img/pic-sidebar1.gif"" width="200" name="MyImage"/>
<?php } elseif (is_page('50')) { ?>
<img src="<?php bloginfo('template_url'); ?>/img/pic-sidebar2.gif"" width="200" name="MyImage"/>
<?php } elseif (is_page('52')) { ?>
<img src="<?php bloginfo('template_url'); ?>/img/pic-sidebar3.gif"" width="200" name="MyImage"/>
<?php } elseif (is_page('54')) { ?>
<img src="<?php bloginfo('template_url'); ?>/img/pic-sidebar4.gif"" width="200" name="MyImage"/>
<?php } else { ?>
<img src="<?php bloginfo('template_url'); ?>/img/pic-sidebar5.gif"" width="200" name="MyImage"/>
<?php } ?>It works fine, but is there a way to attribute this code to a function, and then call upon that function?
Any help much appreciated.
- chivas0
function get_img($page) {
switch($page) {
case is_home():
$pic_num="0";
break;
case 48:
$pic_num="1";
break;
case 50:
$pic_num="2";
break;
case 52:
$pic_num="3";
break;
case 54:
$pic_num="4";
break;
default:
$pic_num="5";
break;
}
return bloginfo('template_url') . '/img/pic-sidebar' . $pic_num . '.gif';
}// call an image like this
echo '<img src="' . get_image(48) . '" width="200" name="MyImage" />';
- Sep0
Thanks Chivas, but I can't get it to work. I try to call to the function as a mouseout event...
onMouseOut="?"
Any thoughts?
But thanks anyway!
- vaxorcist0
some php installations need <?php rather than just <?
- chivas0
I think the PHP4 and 5 no longer require the full <?php tag
- section_0140
I always use <?php ?> . Better safe than sorry (although a search and replace could fix it pretty easy).