• I need some help here.. I’m using a theme called ‘moneyzine’ on moneysinternet.com.

    The theme displays images next to posts. These images are linked via a custom field called ‘screen’ that you add to your posts.

    The problem comes up with you don’t add that custom field to the post, a black image shows up. I’d like a default image to show up.

    The coding that displays the image is in the index.php file under the theme.. It goes like this:

    <div class=”entry”>
    <?php $screen = get_post_meta($post->ID,’screen’, true); ?>
    <?php $screen = get_post_meta($post->ID,’screen’, false); ?>
    <img src=”<?php echo ($screen); ?>” width=”160″ height=”100″ alt=”” />
    <?php the_content_limit(600, “”); ?>
    <div class=”clear”></div>
    </div>

    what would i change to get this display a default image if no custom image is defined?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Pretty easy fix, just add a bit of logic:

    <div class="entry">
    	<?php
    	$screen = get_post_meta($post->ID,'screen', true);
    	$screen = ( !empty( $screen ) ) ? $screen : 'path/to/default-image.jpg';
    	print '<img src="' . $screen . '" width="160" height="100" alt="" />';
    	the_content_limit(600, "");
    	?>
    	<div class="clear"></div>
    </div>

    Please let me know if you have trouble with this code – it works in theory, but was not tested.

    Thread Starter tyankee

    (@tyankee)

    wow – worked great… thank a lot…

    no problem, glad I could help

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_post_meta help’ is closed to new replies.