In desperate need of help: Adding a single “if/else” line to existing code..

Hi everyone,

I have a section of code that I need to add a line to, but every time I do it screws everything up and renders the page blank. It’s entirely possible I’m just doing it wrong, so I figure you guys may be able to add some definitive

Here is the existing code:

[php] <?php }
//if has photos, display photos tab content
if( $has_photo) { ?>


<?php
$i = 0;
//foreach listing photo, create a javascript img object for hover over image change
foreach($listing->photos as $photo) {
echo “”;
$i++;
}
?>



main-slider-photo



<?php $j=0;
//display each one of building photos
foreach ($listing->photos as $photo) {?>

slider-img

<?php $j++;
}?>






<?php }?>


[/php]

What I’m trying to do is add a line of code so that in the event there is no photo, to display the default photo I have. I believe the line of code should look something like this:

[php] else
$imgUrl = “/wordpress/wp-content/themes/realestate_2/ygl-assets/images/nophoto.gif”;
[/php]

My question is… 1) IF correct, where exactly should that line of code be placed? and 2) is there anything else needed to make that line of code work beyond what I’ve posted here (header etc)?

If anyone can help me by replying with a couple lines of code I can copy and paste back into my site to get this over with I’ll gladly shoot you $15 via paypal so you can go buy yourself some lunch or coffee or something. I’m at the end of my rope!

Thanks!!

its already there, if( $has_photo) { just add your no pic thing in an else statement at the last }.

You mean something like this?

[php]<?php }
if( $has_photo) {else
$imgUrl = “my_image_link.gif”;
}
?>[/php]

last brace
[php]

<?php } else { $imgUrl = "my_image_link.gif"; } ?>
	<p>
hello Mrnoob, Add below code between <?php }?>

[php]

<?php }?>

// below code execute if there is image not found

<? else { $imgUrl = "/wordpress/wp-content/themes/realestate_2/ygl-assets/images/nophoto.gif"; echo '
np image
'; } ?>

[/php]

i hope this will helpful for you.
Reply your feedback
SR

ALRIGHT!

So the code that finally got it working was:

[php] <?php }
else {
$imgUrl = “/wordpress/wp-content/themes/realestate_2/ygl-assets/images/nophoto.gif”;
echo ‘

np image
’;
}
?>
[/php]

I tried each one above and initially Richei’s didn’t interfere with the page but it didn’t render the image either (still, a step in the right direction). Then I tried Sarthak’s and it wasn’t working either, so I edited it to look like it does above, placed it in between a different div and now I’m off and running. Thank you both so much I really was about to jump out a window over this. I’ll shoot you both $10 so you can buy a sandwich or coffee or something you’ve both been a HUGE help!

mine was more of a generic example, but i’m glad you got it working :slight_smile: I don’t need payment for this lol, just glad i could help :slight_smile:

Hello Mrnoob, It's really nice to see that finally your issue is resolve. For any other issue you can post here. you will surely get a positive response. :) ~~ SR ~~
Sponsor our Newsletter | Privacy Policy | Terms of Service