February 7, 2012

How to Show Images in Blog Search Results

I have a Pictures Blog and i was wondering if there is a way to show just Images on the Blog Search Results Pages because that would be far more better than the Normal Blog Results where the Blog Post Title & a Small Excerpt would be shown, and in this case just the title would be shown as there is no text in the post. This can give the blog readers a dull look because they would expect beautiful images to be shown on a Photo Blog.

Wordpress Tips

Wordpress Tips

Now here is a solution for this using the Get the Image Wordpress Plugin, which would display Images where ever specified. You need to Install and activate the plugin and then move over to the theme files because you need to make some changes in the Search Results page. This is normally the ‘search.php’ file.

How does it pull images?
1. Looks for an image by custom field (one of your choosing).
2. If no image is found, it grabs an image attached to your post.
3. If no image is attached, it can extract an image from your post content (off by default).
4. If no image is found at this point, it will default to an image you set (not set by default).

How to use the plugin?
First, you should know that there are two types of ways to call the image script, either with function-style parameters or query-string-style parameters. I prefer the former over the latter because it simply works better and is the way I’ll be explaining throughout this guide.

Example with function-style parameters
<?php get_the_image( array( 'custom_key' => array( 'Thumbnail', 'thumbnail' ), 'default_size' => 'thumbnail' ) ); ?>

Example with query-string-style parameters
<?php get_the_image( 'custom_key=Thumbnail,thumbnail&default_size=thumbnail' ); ?>

The image script parameters

By simply making a function call to <?php get_the_image(); ?> within a template file, the script will default to this:
$defaults = array(
'custom_key' => array( 'Thumbnail', 'thumbnail' ),
'attachment' => true,
'default_size' => 'thumbnail',
'default_image' => false,
'order_of_image' => 1,
'link_to_post' => true,
'image_class' => false,
'image_scan' => false,
'width' => false,
'height' => false,
'echo' => true
);

This plugin works best if you use the Custom Image option in wordpress to add your Images and it would be great if it would support grabbing the First Images from the Blog Posts on the Search Result Pages or Category Pages.

We will send you useful technology related Tips. Enter your email address :

Comments

  1. Sagar Gholap says:

    yeah..i googled about it so many times but couldn’t find a working solution for it.
    Now i’ll see whether it works for me and get back to you if it doesn’t.

    [Reply]

  2. Prasanth Chandra says:

    This is a very useful tip. Especially if you have a portfolio or a pictures in your blog.

    [Reply]

Speak Your Mind

*


More in Wordpress Guide (31 of 69 articles)