2 added 92 characters in body
source | link

You have 2 quick options, via the template file using the_post_thumbnail for the loop. I assume your outputting the data in a typical blog format and thus your function above won't work or act very weird inside the loop.

Instead try something like this in the actual template file where your main loop is (maybe index.php or loop.php) :

  //loop starts
   if ( has_post_thumbnail() ) { 
   the_post_thumbnail();
   }
   //the_content(); and other stuff
   //loop ends

Or if you want to use an action instead to alter the main loop you can use pre_get_posts, for example in your functions.php file.

Something like:

add_action( 'pre_get_posts', 'add_featured_image' );

function add_featured_image( $query ) {

    if( $query->is_main_query() && $query->is_home() ) {
        //your image code
    }

}

Notice that the above is checking 2 parameters, the main query and the home page, it is very important to check if it is the main query, otherwise it will alter all queries.

Reference:http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

You have 2 quick options, via the template file using the_post_thumbnail for the loop. I assume your outputting the data in a typical blog format and thus your function above won't work or act very weird inside the loop.

Instead try something like this in the actual template file where your main loop is (maybe index.php or loop.php) :

  //loop starts
   if ( has_post_thumbnail() ) { 
   the_post_thumbnail();
   }
   //the_content(); and other stuff
   //loop ends

Or if you want to use an action instead to alter the main loop you can use pre_get_posts, for example in your functions.php file.

Something like:

add_action( 'pre_get_posts', 'add_featured_image' );

function add_featured_image( $query ) {

    if( $query->is_main_query() && $query->is_home() ) {
        //your image code
    }

}

Notice that the above is checking 2 parameters, the main query and the home page.

Reference:http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

You have 2 quick options, via the template file using the_post_thumbnail for the loop. I assume your outputting the data in a typical blog format and thus your function above won't work or act very weird inside the loop.

Instead try something like this in the actual template file where your main loop is (maybe index.php or loop.php) :

  //loop starts
   if ( has_post_thumbnail() ) { 
   the_post_thumbnail();
   }
   //the_content(); and other stuff
   //loop ends

Or if you want to use an action instead to alter the main loop you can use pre_get_posts, for example in your functions.php file.

Something like:

add_action( 'pre_get_posts', 'add_featured_image' );

function add_featured_image( $query ) {

    if( $query->is_main_query() && $query->is_home() ) {
        //your image code
    }

}

Notice that the above is checking 2 parameters, the main query and the home page, it is very important to check if it is the main query, otherwise it will alter all queries.

Reference:http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

1
source | link

You have 2 quick options, via the template file using the_post_thumbnail for the loop. I assume your outputting the data in a typical blog format and thus your function above won't work or act very weird inside the loop.

Instead try something like this in the actual template file where your main loop is (maybe index.php or loop.php) :

  //loop starts
   if ( has_post_thumbnail() ) { 
   the_post_thumbnail();
   }
   //the_content(); and other stuff
   //loop ends

Or if you want to use an action instead to alter the main loop you can use pre_get_posts, for example in your functions.php file.

Something like:

add_action( 'pre_get_posts', 'add_featured_image' );

function add_featured_image( $query ) {

    if( $query->is_main_query() && $query->is_home() ) {
        //your image code
    }

}

Notice that the above is checking 2 parameters, the main query and the home page.

Reference:http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts