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.
Query WordPress Post:
<?php query_posts('post_type=post&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>

Query WordPress Post from Specific category(sports):
<?php query_posts('post_type=post&category_name=sports&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
Example
<?php 
/*
Template Name: Category Template
*/
get_header(); ?>
<div class="maincontent">
<div class="widthtemp">
<div class="column_one ">
<h2>Posts From Sports Category</h2>
<?php query_posts('post_type=post&category_name=Sports&post_status=publish&posts_per_page=2&paged='. get_query_var('paged')); 
?>
<?php get_template_part('post-loop'); ?>
</div>
<div class="column_two ">
<h2>Posts From Others Category</h2>
<?php query_posts('post_type=post&category_name=Others&post_status=publish&posts_per_page=2&paged='. get_query_var('paged')); ?>
<?php get_template_part('post-loop'); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
Register Custom Post
functions.php:
        function create_post_type() {
                register_post_type( 'testimonial',
                        array(
                                'labels' => array(
                                        'name' => __( 'Testimonial' ),
                                        'singular_name' => __( 'Testimonial' ),
                                        'add_new' => __( 'Add New' ),
                                        'add_new_item' => __( 'Add New Testimonial' ),
                                        'edit_item' => __( 'Edit Testimonial' ),
                                        'new_item' => __( 'New Testimonial' ),
                                        'view_item' => __( 'View Testimonial' ),
                                        'not_found' => __( 'Sorry, we couldn't find the Testimonial you are looking for.' )
                                ),
                        'public' => true,
                        'publicly_queryable' => false,
                        'exclude_from_search' => true,
                        'menu_position' => 14,
                        'has_archive' => false,
                        'hierarchical' => false,
                        'capability_type' => 'page',
                        'rewrite' => array( 'slug' => 'testimonial' ),
                        'supports' => array( 'title', 'editor', 'custom-fields' )
                        )
                );
        }
 add_action( 'init', 'create_post_type' );

Note: One can add many field:
   'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' )

Query Post in Custom Page Template:
<?php query_posts('post_type=testimonial&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>

Example
<?php 
/*
Template Name:Testimonial
*/
get_header(); ?>
<div class="breadcrumbs">
<?php if (function_exists('wordpress_breadcrumbs')) wordpress_breadcrumbs(); ?>
</div>
<div class="maincontent">
<?php get_sidebar();?>
<div class="content ">
<?php query_posts('post_type=testimonial&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); 
   ?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>      
<h2 id="testimonil_title">Testimonial</h2>
 <div class="single_testimonial fix">
<div class="client_comments">
<?php the_content();?>
</div>
<div class="client_name">
<?php the_title();?>
</div>
</div>
<?php endwhile; ?>    
<?php endif; ?>
</div>
</div>
<?php get_footer();?>
Note
One can query to show one post in homepage( creating a testimonial option) and give link to the custom template page to show more.

<div class="content ">
<php 
query_posts('post_type=testimonial&post_status=publish&posts_per_page=1&paged='. get_query_var('paged')); 
   ?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>      
<h2 id="testimonil_title">Testimonial</h2>
  <div class="single_testimonial fix">
<div class="client_comments">
<?php the_content();?>
</div>
<div class="client_name">
<?php the_title();?>
</div>
</div>
<?php endwhile; ?>    
<?php endif; ?>
</div>
Blog post Query anywhere specially in widget:
<?php
global $post;
$args = array( 'posts_per_page' => 2, 'post_type'=> 'post' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<div class="single_footer_left fix">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</div>
<?php endforeach; ?>

Blog post Query From Specific Category:
<?php
query_posts('showposts=1&cat=3');
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<ul>
               <li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>      

<!-- Your Post Query here -->

<?php endwhile; ?>  
  <?php endif; ?>
Example
<div class="content">
       <?php if(have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>      

<!-- Your Post Query start -->  
<div class="post" id="post-<?php the_ID(); ?>">
<div id="post-title" class="fix">
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
</div> <!-- end div .post-title -->
<div class="breadcumbs fix">
<?php if (function_exists('wordpress_breadcrumbs')) wordpress_breadcrumbs(); ?>
</div>
<div class="entry fix">
<?php the_post_thumbnail('post-image', array('class' => 'single-post')); ?>
<?php the_content(); ?> 
<div class="space fix">
<?php get_template_part( 'postmeta' ); // Post Meta (postmeta.php) ?>
</div>

<?php comments_template( '', true ); ?>  
</div> <!-- end div .entry -->
</div> <!-- end div .post -->
<!-- Your Post Query end -->

<?php endwhile; ?>    
<?php endif; ?> 
 </div>
<div id="copyright">
            <?php if(!empty($data['custom_copyright'])) { 
               echo $data['custom_copyright'];
              }
              else { ?>
            &copy; <?php _e('Copyright', 'freedombd'); ?> <?php echo date('Y'); ?> <a href="<?php echo home_url(); ?>/" title="<?php bloginfo('name'); ?>" rel="home"><?php bloginfo('name'); ?></a>
            <?php } ?>
        </div>
<?php global $data; ?>
<?php if($data['logo_uploader']): ?>
<a href="<?php bloginfo( 'home' ); ?>">
<img src="<?php echo $data['logo_uploader']; ?>" alt=""/>
</a>
<?php else: ?>  
<h1>
<a href="<?php echo home_url(); ?>/" title="<?php bloginfo( 'name' ); ?>" rel="home">
<?php bloginfo( 'name' ); ?>
</a>
</h1>
<div id="site-description"><p><?php bloginfo('description'); ?></p></div>
<?php endif; ?>
WP Custom Template
<?php
/*
Template Name: Single Blog Post Template
*/
get_header(); ?>
=================>  OR  <================
<?php
/**
 * @package WordPress
 * @subpackage freedom Theme
 * Template Name: Blog
 */
?>
<?php get_header(); ?>
Example
<?php
/**
 * @package WordPress
 * @subpackage freedom Theme
 * Template Name: Blog
 */
?>
<?php get_header(); ?>
<?php
//start page loop
if (have_posts()) : while (have_posts()) : the_post();

//get slider meta
$page_slider = get_post_meta($post->ID, 'office_page_slider', true);

//show page slider if enabled
if ($page_slider == 'enable') {
//get slider template
get_template_part( 'includes/page-slides');
}

//get meta to set parent category
$blog_filter_parent = '';
$blog_parent = get_post_meta($post->ID, 'office_blog_parent', true);
if($blog_parent != 'select_blog_parent') { $blog_filter_parent = $blog_parent; } else { $blog_filter_parent = NULL; }
?>

<header id="page-heading">
<h1><?php the_title(); ?></h1>
    <?php if($data['disable_breadcrumbs'] !='disable') { office_breadcrumbs(); } ?>
</header>
<!-- /page-heading -->

<div class="post clearfix">
<?php
//tax query
if($blog_filter_parent) {
$tax_query = array(
array(
 'taxonomy' => 'category',
 'field' => 'id',
 'terms' => $blog_filter_parent,
 )
);
} else { $tax_query = NULL; }

    //query posts
        query_posts(
            array(
            'post_type'=> 'post',
            'paged'=>$paged,
'tax_query' => $tax_query
        ));

//loop
    if (have_posts()) :
//get entry template
get_template_part( 'loop', 'entry');            
    endif;

//show pagination
pagination();

//reset query
wp_reset_query(); ?>

</div>
<!-- /post -->

<?php endwhile; endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
WP Post Excerpt-01
functions.php
function excerpt($num) {
  $limit = $num+1;
  $excerpt = explode(' ', get_the_excerpt(), $limit);
  array_pop($excerpt);
  $excerpt = implode(" ",$excerpt)." <a href='" .get_permalink($post->ID) ." ' class='".readmore."'>Read       More</a>";
  echo $excerpt;
}
Call Function: <?php echo excerpt('15'); ?>
WP Post Excerpt-02
functions.php
function new_excerpt_length($length) {
 return 100;
 }
 add_filter('excerpt_length', 'new_excerpt_length');

 function new_excerpt_more( $more ) {
  return ' Read More';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );

Call function:
 the_excerpt() ;
WP Post Excerpt-03
functions.php
function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);

   if (strlen($_GET['p']) > 0) {
      echo $content;
   }

   else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content;
        echo $content;
        echo "&hellip;</p>";
        echo "<span class=\"readmore\"><a href=\"";
        the_permalink();
        echo "\">".$more_link_text."</a></span>";
   }
              else {
                     echo $content;
                    }
}
Call function:
<?php the_content_limit(400, "Read More") ?>
Excerpt Example
<?php get_header(); ?>
<div class="internal_page">
<div class="stracture">
<div class="content floatleft">
<div class="breadcumbs">
<?php if (function_exists('wordpress_breadcrumbs')) wordpress_breadcrumbs(); ?>
</div>
<?php if(have_posts()) : ?><?php while(have_posts())  : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<?php the_post_thumbnail('post-image', array('class' => 'imgthumb')); ?>
<div id="post-title" class="fix">
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
</div> <!-- end div .post-title -->

<div class="entry">
<?php the_excerpt(); ?> 
or 
<div class="blogexcerpt"><?php echo excerpt('58'); ?></div>
<div class="space">
<?php get_template_part( 'postmeta' ); // Post Meta (postmeta.php) ?>
</div>

<?php comments_template( '', true ); ?>
</div> <!-- end div .entry -->
</div> <!-- end div .post -->

<?php endwhile; ?>

<?php else : ?>
<div class="post">
<h3><?php _e('404 Error&#58; Not Found', 'imran_business'); ?></h3>
</div>
<?php endif; ?>

</div>

<?php get_sidebar(); ?>

</div>
</div>

<?php get_footer(); ?>
Back To Top