Hi Friends, Today I am going to write about a plugin which is very useful to get image of post by ID, I know there are so many functions or methods exists to get image from content of post or get featured image but all are not exists in one function means you can’t get image like first check custom field , if not found check featured image , if not found scan content , if not found check for an image by attachment and lastly no image found then show default image, it means this plugin searching all things in a post for image and if image found it shows images and if not found then it shows default image.
Get The Image is a wordpress plugin by which any wordpress developer can handled images for posts very easily because this plugins searches images of post for all possibilities and show it. I was searching this type of functionality from so many days and finally I found this couple of days ago, So I thought to share it with world. So if you want to handle images of post easily then this plugin is best option for you because it search image for a post for all possibilities and return tag with image.
This plugin having so many options and many styles to call function in this, You have to just install this plugin and after installing below are the details of how to use plugin or plugin function :
Example with function-style parameters
<?php get_the_image( array( 'custom_key' => array( 'Thumbnail', 'thumbnail' ), '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,
'size' => 'thumbnail',
'the_post_thumbnail' => true,
'default_image' => false,
'order_of_image' => 1,
'link_to_post' => true,
'image_class' => false,
'image_scan' => false,
'width' => false,
'height' => false,
'echo' => true
);
– custom_key
This parameter refers to a custom field key (or keys) that you use. Remember, custom field keys are case-sensitive (defaults are Thumbnail and thumbnail).
attachment
The script will look for images attached to the post (set to true by default).
– size
This refers to the size of an attached image. You can choose between thumbnail, medium, large, full, or any custom image size you have available (the default is thumbnail).
– the_post_thumbnail
This refers to the WordPress 2.9’s new the_post_thumbnail() feature. By having this set to true, you may select an image from the post image meta box while in the post editor.
– default_image
Will take the input of an image URL and use it if no other images are found (no default set).
– order_of_image
You can choose for the script to grab something other than the first attached image. This only refers to image attachments.
– link_to_post
Whether the attachment image should be linked to the post (set to true by default).
– image_class
You can give an additional class to the image for use in your CSS.
– image_scan
If set to true, the script will search within your post for an image that’s been added.
– width
Set the width of the image on output.
height
Set the height of the image on output.
– echo
If set to true, the image is shown on the page. If set to false, the image will be returned to use in your own function. (Set to true by default.)
Some examples of how to use this plugin
Example 1: Let’s suppose that you want to add thumbnails to your category archive pages. What you’ll need to do is open your category.php file and add this code within the Loop:
<?php get_the_image(); ?>
By default, that will look for an image with the custom field key Thumbnail and thumbnail. If that image doesn’t exist, it will check if a post image has been set. If that image doesn’t exist, it will search for any images attached to your post.
Example 2: Let’s suppose you want a full-sized image and maybe you want to grab it by a custom field key of Feature. Depending on your theme, this will need to go within the Loop in whatever file is calling the featured article.
<?php get_the_image( array( 'custom_key' => array( 'Feature' ), 'size' => 'full' ) ); ?>
If no feature image exists by custom field, it will look for images attached to your post.