Home > Creative Design, Get Post Image, Web Designer Tips, Wordpress, Wordpress Customization, Wordpress Plugins, Wordpress Post Images, Wordpress Templates > Using Get Post Image Plugin to optionally show an image on your home page

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

September 30th, 2009 Mayur Jobanputra

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

  1. September 30th, 2009 at 16:43 | #1

    Thanks for the plug :)

    As an alternative you can also use gpi_get_image_count() to determine if any images are present in a post.

  2. September 30th, 2009 at 17:37 | #2

    Ah. I didn’t realize that :) Oh well. Now readers know!

Comments are closed.