Learn Dreamweaver

Display Featured Image in Post/Page

by monstertutor

Featured image in WordPress is an amazing feature. It let’s you upload an image that can be used as a thumbnail or any photo for your post or page.

To get the featured image and show it on the page, use the code below:

<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();	
} 

else{ ?>

<img width="290" height="198" border="0" class="wpp-thumbnail" alt="" src="<?php bloginfo('template_url'); ?>/images/no_thumb.jpg">	
<?php	}
?>

I also included a code to show if the featured image doesn’t exist. In the sample above it will show a default image.

Related posts:

Show Posts by Category in WordPress
Email Template Tester
Increase WordPress Upload Limit
CSS Styling element inside an iframe using javascript

Recommended Web Design Books!


Category: Wordpress
Tags: cheat sheet, coding, wordpress template


Special Offer! $8.99 .COMs or .Nets now at GoDaddy!