Why is my <?php the_post_thumbnail(); ?> not bringing up any images on my wordpress page?

my code is

<?php
// Template Name: homepage
get_header(); ?>
    <div id="content" class="full-width">

<?php 
    query_posts(array( 
        'post_type' => 'avada_portfolio',
        'showposts' => 2 
    ) );  
?>
<?php while (have_posts()) : the_post(); ?>
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>


    <img src=" <?php the_post_thumbnail('medium'); ?>">
        <p><?php echo get_the_excerpt(); ?></p>
 <?php
    endwhile; //resetting the page loop
    wp_reset_query(); //resetting the page query
    ?>


<h1 class="entry-title"><?php the_title(); ?></h1> <!-- Page Title -->
    <?php
    // TO SHOW THE PAGE CONTENTS
    while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
        <div class="entry-content-page">
            <?php the_content(); ?> <!-- Page Content -->
        </div><!-- .entry-content-page -->

    <?php
    endwhile; //resetting the page loop
    wp_reset_query(); //resetting the page query
    ?>

<?php get_footer(); ?>

I have added the <?php add_theme_support( 'post-thumbnails' ); ?> to functions however it just shows a broken image on my home page 🙁

Read More

All my images are uploaded onto my wordpress site and set as featured images on the custom post!

thanks

Related posts

Leave a Reply

3 comments

  1. the_post_thumbnail('medium') this function will return img tag with feature image.

    So you can get image following two ways:-

    <img src=" <?php echo wp_get_attachment_url(get_post_thumbnail_id( $post->ID ), 'medium' ); ?>">
    

    OR just this function :- <?php the_post_thumbnail('medium'); ?>

    Hope this will help you.

  2. <img src=" <?php the_post_thumbnail('medium'); ?>">
    

    This does not work in <img src="">. For me this worked:

    <img src=" <?php echo wp_get_attachment_url(get_post_thumbnail_id( get_the_ID() ), 'thumbnail' ); ?>" class="media-object" style="width:73px; height:73px">
    
  3. write “the_post_thumbnail(‘medium’);” out of the image tag

    Like this:

    <?php while (have_posts()) : the_post(); ?>
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
        <?php the_post_thumbnail('medium'); ?>
        <p><?php echo get_the_excerpt(); ?></p>
    
    <?php
        endwhile; //resetting the page loop
        wp_reset_query(); //resetting the page query
    ?>