post thumbnails appear in some pages

Is there a way to have thumbnail images appear with a post? I am using a gravity form which users can upload a post with a thumbnail. The thumbnail appears on the page where the posts are, but not on other places like the home page.....

  • Chris
    • The Bug Hunter

    You can use get_posts in your template:

    $r = new WP_Query(array('showposts' => $show, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
    if ($r->have_posts()) :
    while ($r->have_posts()) : $r->the_post(); ?>
    <div class="upcoming" style="margin-bottom:25px; padding:0 5px 5px 20px;">
    <?php $args = array(
       	'post_type' => 'attachment',
       	'numberposts' => 1,
       	'post_status' => null,
       	'post_parent' => $post->ID
           $attachments = get_posts($args);
          if ($attachments) {
            foreach ($attachments as $attachment) {
               ?> <a style="border:none;" href="<?php the_permalink() ?>">
               <?php echo wp_get_attachment_image($attachment->ID, 'front-thumb'); ?>
               </a> <?php
         <p><a style="color:red; text-decoration:none; text-align:left;" href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></p>
    <?php endwhile; ?>
    wp_reset_query();  // Restore global post data stomped by the_post().
    endif; ?>
  • Philip John
    • DEV MAN’s Apprentice

    To include a thumbnail added using the standard featured image functionality you'll just need to ensure that the_post_thumbnail() in the template files.

    I'm unaware if Gravity uses the standard featured image but you can check that by simply editing your post.


  • Chris
    • The Bug Hunter


    My code wasn't the cleanest, since it has loads of shoddy inline formatting, due to tacking something onto a client's original horrific design! I can take you through it...

    NB. I am showing you how to edit your theme files. Ideally you should create a child theme, so any changes you make don't break your current theme. However if you copy any files you edit into notepad, then you won't lose them if you make a mess!

    1. Firstly, go select a post, and load it in the edit mode in the Admin Area of WordPress.
    2. Check if the featured image down on the bottom right is filled.
    3. If it is, that means that Gravity uses featured images.
    4. If that's the case, go to Appearance -> Editor.
    5. Find the template you want to edit: if in doubt, for home, its usually index.php
    6. Add the code the_post_thumbnail() where you want it to appear, ie, between <?php while (have_posts()) : the_post(); ?> and <?php endwhile; ?>.

    Hopefully that should place the featured image for you. If it doesn't have featured images, come back to me!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.