Archive

Archive for the ‘Get Post Image’ Category

Using Get Post Image Plugin to optionally show an image on your home page

September 30th, 2009 Mayur Jobanputra 2 comments

image

Get Post Image is a plugin I recently found that let’s you you place an image from a post into your home page to entice visitors to read your post.  I found a trick to OPTIONALLY show an image if it’s found, and not show one if it isn’t.  I used the PHP command “strpos” which allows me to search for the default.jpg and not show it if my post doesn’t contain an image.

Installation Instructions:

  1. Download the plugin from http://www.andrewgrant.org/get-post-image
  2. Install and activate the plugin as with any other WordPress installation
  3. Determine where you want your image thumbnail to appear (usually on your home page as I have done here), and find your post loop (the

<?php
    $image_tag = gpi_get_image(0,http://www.site.com/default.jpg, "portfolio-image");
    $url = get_permalink();
    $pos = strpos($image_tag,"http://www.site.com/default.jpg");
    if($pos === false) {
        echo "<a href=’$url’ class=preview>$image_tag</a>";
         // string needle NOT found in haystack
    }
    else {
         // string needle found in haystack
    }
    ?>
<?php the_excerpt(‘Read the rest of this entry &raquo;’); ?>

 

If you need more help with installing/configuring this plugin, let me know.  Just shoot me an email if you like.

Related Posts with Thumbnails

Post to Twitter Tweet This Post