Display Custom Field Data:
<?php $key="url"; echo get_post_meta($post->ID, $key, true); ?>

Custom field show when only image exist:
<?php $image = get_post_meta($post->ID, 'url', true);
if($image) : ?>
<p><?php $key="url"; echo get_post_meta($post->ID, $key, true); ?></p>
<?php endif; ?>

Display custom field if exists:
<?php $image = get_post_meta($post->ID, 'url', true);
if($image) : ?>
<img src="<?php echo $image; ?>" alt="" />
<?php endif; ?>

Conditional Custom Field:
<?php
$url = get_post_meta( $post->ID, 'url', true );
if ( $url ) {
    echo $url;
} else {
    the_permalink();
}
?>
Example(loop.php)
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>    
<div class="single_post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="post_info">
Posted In: <?php the_category(', '); ?> | Posted on: <?php the_time('M d, Y') ?> <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?>
</div>
<div class="post_content">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('post-image', array('class' => 'post-thumb')); ?></a>
<?php echo excerpt('60'); ?>
</div>
<?php $image = get_post_meta($post->ID, 'url', true);
if($image) : ?>
<p style="background:#ddd; color:#000;padding:10px;">
               <?php echo $image; ?></p>
           <?php endif; ?>

OR (conditional)
<?php $image = get_post_meta($post->ID, 'url', true);
if($image) : ?>
<p style="background:#ddd; color:#000;padding:10px;">
<?php $url = get_post_meta( $post->ID, 'url', true );
if ( $url ) {echo $url;

else {the_permalink();?>
</p>
<?php endif; ?>
</div>
<?php endwhile; ?>  
<?php endif; ?>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts') ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>') ); ?></div>
Example(page.php)
<?php get_header(); ?>
<div class="maincontent">
<div class="page_header_image">
<?php  $image = get_post_meta($post->ID, 'url', true);
if($image) : ?>
<img src="<?php echo $image; ?>" alt="" />
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<div class="content">
<?php if(have_posts()) : ?><?php while(have_posts())  : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('404 Error&#58; Not Found'); ?></h3>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>

NOTE: One can use custom field to bring any image in any of a wp theme suppose any position of a page. Here is an example for header area of a theme.
Back To Top