How to show post thumbnail in wordpress?

by 3 replies
4
I am using wordpress and I developed my own theme for wordpress. Now I would like to show the thumbnail of one of the images uploaded for the post. I used
PHP Code:
<?php echo get_the_post_thumbnail($post->ID'thumbnail'); ?>
to fetch that but thrown error by the compiler. How do I get the img src for the thumbnails in wordpress?
#programming #post #show #thumbnail #wordpress
  • First, make sure post thumbnails are enabled in your theme. In the theme functions.php file add this:
    Code:
    if ( function_exists( 'add_theme_support') )
      add_theme_support('post-thumbnails');
    Then in your templates you can call the image in several ways. The easiest:
    Code:
    if ( has_post_thumbnail() )
      the_post_thumbnail();
    The above will output an img tag with the proper src address.

    The main Codex page for post thumbnails: Post Thumbnails « WordPress Codex
    • [1] reply
    • @SteveJohnson Thanks for you help.
      This works well when one of the images is selected as thumbnail. What if no image is selected as thumbnail and want to fetch the thumbnail of first image in the post.
      • [1] reply

Next Topics on Trending Feed

  • 4

    I am using wordpress and I developed my own theme for wordpress. Now I would like to show the thumbnail of one of the images uploaded for the post. I used PHP Code: <?php echo get_the_post_thumbnail($post->ID, 'thumbnail'); ?> to fetch that but thrown error by the compiler. How do I get the img src for the thumbnails in wordpress?