Posted By

thehamilton on 11/11/09


Versions (?)

Display Thumbnails Next To Your Posts

 / Published in: PHP

Start by creating a default image in Photoshop or Gimp. The size in my example is 200×200 pixels but is of course up to you. Name the image default.gif.

Upload your default.gif image to the image directory in your theme.

Open the index.php file and paste in the following code where you’d like the thumbnails to be displayed:

Save the file.

In each of your posts, create a custom field called post-img. Set its value as the URL of the image you’d like to display as a thumbnail.

  1. <?php $postimageurl = get_post_meta($post->ID, 'post-img', true);
  2. if ($postimageurl) {
  3. ?>
  4. <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php echo $postimageurl; ?>" alt="Post Pic" width="200" height="200" /></a>
  5. <?php } else { ?>
  6. <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php bloginfo('template_url'); ?>/images/wprecipes.gif" alt="Screenshot" width="200" height="200" /></a>
  7. <?php } ?>

Report this snippet  

You need to login to post a comment.