WordPress.org

Ready to get started?Download WordPress

Forums

Can't echo the_post_thumbnail (3 posts)

  1. TootsieRoll
    Member
    Posted 2 years ago #

    For some reason I can't seem to get this small block of code to work. I'm trying to show the most recent post with it's content and thumbnail. I had no problem displaying the title and content, but the thumbnail just won't show.

    So this is in my template:

    <?php
    		$args = array( 'numberposts' => '1' );
    		$recent_posts = wp_get_recent_posts( $args );
    		foreach( $recent_posts as $recent ){
    
    			echo '<h5>' .  $recent["post_title"].'</h5> ';
    			echo '<br />';
    			echo '<p>' .$recent["post_content"].'</p>';
    			echo '</div>';
    			echo '<div class="left">';
    			 if (has_post_thumbnail()){
           		 echo 'the_post_thumbnail';
           		 }
    			echo '</div>';
    		}
    ?>

    And of course I have this in functions.php
    add_theme_support('post-thumbnails');

    Any Ideas? Thanks

  2. TootsieRoll
    Member
    Posted 2 years ago #

    I also tried this:

    <?php
    		$args = array( 'numberposts' => '1' );
    		$recent_posts = wp_get_recent_posts( $args );
    		foreach( $recent_posts as $recent ){
    
    			echo '<h5>' .  $recent["post_title"].'</h5> ';
    			echo '<br />';
    			echo '<p>' .$recent["post_content"].'</p>';
    			echo '</div>';
    			echo '<div class="left">'. $recent["the_post_thumbnail"].'</div>';
    
    		}
    ?>

    Still not showing

  3. farvardin
    Member
    Posted 1 year ago #

    test this

    $pic = get_the_post_thumbnail($recent["ID"], "medium");

Topic Closed

This topic has been closed to new replies.

About this Topic