Skip to main content

Using Featured Image in WordPress

Today there are innumerable blogs on any topic you would choose. If you are a blogger your main priority would be to make your blog, stand out! Make it more attractive and tempt people to read what you right.

One of the most important technique that major blogs use is setting a featured image for each post.
This can be achieved very easily as it 's there in-built in wordpress. But you have to enable it in functions.php file within your theme folder.

Here is how you do that:
add_theme_support( 'post-thumbnails' );
Paste this within your functions.php file.

Additionally you can specify which should have this feature in an array like this:
// Add it for posts
add_theme_support( 'post-thumbnails', array( 'post' ) );
// Add it for pages
add_theme_support( 'post-thumbnails', array( 'page' ) );


You also additional control over this, you explicitly decide the dimension or hard crop the thumbnails etc.
The dimension can be set like this:
//the scale is pixels by default
set_post_thumbnail_size( 50, 50 );


Cropping can be achieved by this piece of code:
//the scale is pixels by default
set_post_thumbnail_size( 50, 50, true );


To get the featured image in your theme just add this in your loop:

//setting only the width or height will help you preserve
//design if you have not set to resize the image
<?php if (has_post_thumbnail()) { ?>
<img src="<?php echo $image[0]; ?>" width="238"/>
<?php } ?>


For people who want to know more further information on this is available in the following links:
  1. Wordpress Official Page on the topic: here
  2. Web6.org write up on this: here
  3. Blogging Tips write up : here
Hope this article served its purpose. For any queries please do use the comment form below.

Comments

Popular posts from this blog

Effective Comment Management in Wordpress

Each people have their on reasons to ask for more control over the comment system, some people want to allow commenting on some posts while some want to close it on some. Some need extra features in comments like subscription or rich text. For some the problem is spam. Here is a random list of plugins that solve these issues. Plugins to combat Fight Spam: Akismet – Anti-spam is a plugin from the creators of WordPress that uses a central database of spam comments to flag spam. Requires a free API key from WordPress.com Spam Karma – Analyzes comments for spam based on a karma system in place. Bad Behavior – Prevents the spambots from even accessing your site by analyzing their HTTP requests. Did You Pass Math? – Asks the commentators a simple math question before their comments are posted. Comment Timeout – Closes comments on all old posts. Encourage Commenting BlogFollow – Shows a snippet of the commenter’s blog at the bottom of the comment. DoFollow – Removes “n...

Using WordPress Comment Meta

Comment meta is such a wonderful addition to WordPress that allow us to extend the native comment form with additional fields. This comes very handy for the one's who is trying to create review sites etc. Unfortunately there’s no documentation added on the WP codex. For the purpose of demonstration we will be doing: add a check box to the comments form. show in the WordPress comments admin whether or not the checkbox was selected. indicate in the comment notification email whether or not the checkbox was selected. Adding the checkbox to the comments form is easy. To add the checkbox to the comments form open up your themes comments.php file and paste this into the area where you need it: <label><input id="publishc" name="publishc" tabindex="90" type="checkbox" value="this is the value I want to capture" /> Whatever sentence that you want commenters to use the checkbox for</label> Now that the checkbox...

Insert Ads, Images or anything in RSS Feeds in WordPress

Monetizing RSS feeds has becomw a common practice, and many blogs do it to maximize their income. FeedBurner can insert AdSense ads into your feed items, but you need at least 500 subscribers to qualify, and you can’t use any ads other than the AdSense ads provided by FeedBurner. So what is the workaround? What if you want to show images in the feeds? Well thats quite easy! Follow these simple steps to perform this hack: Edit the functions.php file of your theme. If your theme doesn’t have a functions.php file, simply create one. Paste the following code into your functions.php file: <?php function insertAds($content) { $content = $content.'<hr /><a href="http://www.wprecipes.com">Have you visited WpRecipes today?</a><hr />'; return $content; } add_filter('the_excerpt_rss', 'insertAds'); add_filter('the_content_rss', 'insertAds'); ?> Save the file. You’re now displaying your ads in your RSS feed! ...