0

I have added Featured image support for my posts by adding the following in the functions.php

add_theme_support('post-thumbnails');

I created 3 posts with Featured Image and i want to display them on the homepage as show in the Read Section in this link http://play.mink7.com/sophiance/

I am trying to do the following to get my posts.

    $args = array(
            'post_type' => 'post',
            'posts_per_page' => 3,
            'order' => 'asc'
            );

    $home_shows = new WP_Query($args);
     //   var_dump($home_shows);

    echo "<pre>";
    print_r($home_shows->posts);
echo "</pre>";

I am trying to fetch the Featured Image using the following syntax.

    $page = get_page(1);
    print_r($page);
    if ( has_post_thumbnail() ) {
       the_post_thumbnail(array(486,226));
    } 
the_content();

Now i am not sure how to call the featured image to the posts i have queried at the top. as the content is already fetched before am calling the featured image.

1

Start by cleaning up your code;

$args = array(
        'post_type' => 'post',
        'posts_per_page' => 3,
        'order' => 'asc'
        );

$home_shows = new WP_Query($args);

//setup your loop here
if( $home_shows->have_posts() ):
    while( $home_shows->have_posts() ): $home_shows->the_post();

    //fetch featured image if exists
    if ( has_post_thumbnail() ) {
       the_post_thumbnail(array(486,226)); 
    }  

    //fetch content 
    the_content();

    //etc...

    endwhile;
endif;

What output do you see?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.