Amit Bhawani Blog

Stay Updated!

Powered by Genesis

You are here: Home / Wordpress Guide / How to Show Images in Blog Search Results

How to Show Images in Blog Search Results

October 15, 2009 by Amit Bhawani

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.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook

Related

About

My name is Amit Bhawani and here I like to share my internet/tech experience with my online readers. You can follow me on Twitter, Facebook & Instagram at @AmitBhawani I am also the Editor-in-Chief of PhoneRadar & Master Gadgets

About Amit Bhawani

My name is Amit Bhawani and here I like to share my internet/tech experience with my online readers. You can follow me on Twitter, Facebook & Instagram at @AmitBhawani

Comments

  1. Sagar Gholap says

    January 10, 2010 at 4:46 am

    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.

  2. Prasanth Chandra says

    January 11, 2010 at 4:41 am

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

  3. Michael Peters says

    December 27, 2012 at 9:38 pm

    Thanks! This is the only thing that has worked for me.

Timeline

Check out Just EV Tweets by @amitbhawani

Recommended To Read

  • How to Find your WiFi Signal Strength & Dead spots in your Home – Best Apps
  • The Wuhan Corona Virus Effect in India – How to Stay Safe
  • This Blogger Lost 25Kgs with this Secret Strategy that Includes a Fitness Tracker
  • Making Money on YouTube, MCN, Useful Tools, Tips & Success Stories
  • The #JaguarPerformance Experience that was Mind Blowing