Only show an image if the custom field exists
-
Hi
I’m trying to make it so that if a post has an image linked to it via a custom field, then it is displayed above the post. If there is no image linked to the file, then nothing is displayed. As the formatting for images in this div uses a border, when there is no image linked you get a 1px wide box above the post. I know I need to use an if statement, but I must be getting the syntax wrong as it either doesn’t do anything, or stops the page from parsing. Appreciate any help.
<?php $image = get_post_meta($post->ID, 'image', true); ?> <img src="<?php echo $image; ?>"/> <h2><?php the_title(); ?></h2> <?php the_content('<p class="serif">Read the rest of this entry »</p>'); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Only show an image if the custom field exists’ is closed to new replies.