Enhance Your WordPress Post Thumbnails in 5 Minutes Using CSS

In: web design

16 Feb 2010


WordPress finally introduced a Post Thumbnail feature in version 2.9 which has made life quite a bit easier for WordPress theme developers that love to integrate thumbnails into their themes. There are many different ways to dress up post thumbnail images, but for this tutorial we are going focus on a simple 5 minute technique using CSS. If you haven’t already integrated post thumbnails into your WordPress theme, there are several detailed tutorials out there that show you how do to so. Here are two in particular that you may want to read by Justin Tadlock and Matt Brett.

Create a Transparent Hover Image

Using my latest TV Elements theme as an example, I’m going to show you how I added the transparent hover image over the post thumbnails used throughout the theme. The TV Elements theme uses 200px wide by 150px high post thumbnail images which I pre-set within my theme options (as described within Matt Brett’s tutorial). So, the first thing we want to do is create a transparent PNG image that we can use to display over the post thumbnail.

Post Images

For this example, the image you create should be exactly the same width as your thumbnails but twice the height so that we can create a simple “hover” state using CSS for each thumbnail. I have uploaded the source hover image file used for the TV Elements theme for your reference.

Some Very Simple CSS

It really is amazing how easy it is to create elegant eye-catching effects using just a few lines of CSS code. The first thing we want to do is create a container for our post thumbnails.

/** The Post Thumbnails Container **/
.post-thumbnail {
width: 200px;
height: 150px;
float: left;
margin: 0 20px 0 20px;
}

Next, lets add the CSS needed for the actual post thumbnail hover image.

/** For The Thumbnail Hover Image **/
.post-thumbnail-frame {
background: url(images/post-thumbnail-frame.png) 0 0;
width: 200px;
height: 150px;
position: absolute;
}

/** Show The Hover State **/
.post-thumbnail-frame:hover {
background: url(images/post-thumbnail-frame.png) 0 -150px;
}

Time for Theme Integration

Now the only thing left to do is to integrate all the above into your WordPress theme. This is much easier than you might think. For instance of you wanted to integrate this effect on your multi-post pages beside your post text, you would edit index.php and insert the following code right above the <?php the_content(' '); ?> tag.

<div class="post-thumbnail">
  <a class="post-thumbnail-frame" href="<?php the_permalink() ?>"
         title="<?php the_title_attribute(); ?>"></a>
  <?php the_post_thumbnail(); ?>
</div>

Go to Source

5 Responses to Enhance Your WordPress Post Thumbnails in 5 Minutes Using CSS

Avatar

Inna

March 5th, 2010 at 2:04 am

Like I want to switch the position of my sidebar from left to right to make it ease and better, so if you see this code in your CSS section
#sidebar {
Width: 250px;
Float: left;
Padding: 8px 0;
Margin: 0;
Word-wrap: break-word; /* fix for long text breaking sidebar float in IE */overflow: hidden; /* fix for long non-text content breaking IE sidebar float */}
Just replace the left with right, like float: right;

Then I want to change my existing background since my background is a form of image so this is the code you need to locate on your CSS
#main-bot {
Width: 1150px;
Height: 50px;
Background: #FFF3DB no-repeat top left;
Margin: 0;
Padding: 0;
Display: block ;}
I remove the url of the image and I replace it with color background like background: #CCCCCC or if your background is not a form of image, you can do the same.

Finally, I want to widen my background space to make it not too narrow, so I need to find the #header-wrapper, #outer-wrapper, #main-wrapper and #sidebar-wrapper, you just simply change the width size of it, like width:660px; to width:700px.

Avatar

caffinated_christmaslights

March 11th, 2010 at 1:34 pm

you might have to first get the program paint.net. it's like photoshop, but free and in my opinion, a little more user friendly. next, you might have to convert the image to a jpg or bmp, as i dont believe it will accept png files. to convert just open it up in the paint program that comes with windows and save as jpg or other file type. when that's done open it with paint.net and right click the layer view of the pic and select the opacity (transparency) by moving the slider bar. save the pic and that should do it for you. good luck and hope that helps.

Avatar

ds37x

March 18th, 2010 at 8:41 pm

From the "file" menu, pull down to "export." png should be one of your file type options there.

Avatar

tarek m

March 19th, 2010 at 12:59 am

I'd be more inclined to worry about the dumbing down effect on the kids watching too much tv. Get them to read or be creative instead.

Avatar

h&mchick

March 19th, 2010 at 7:40 am

they need to concent…

but considering people do that to celebrities, sure.

annnddd you may not want to… she'll find out…… dunno if you want that or not.

Comment Form

About this blog

This blog delivers stylish and dynamic news for designers and web-developers on all subjects of design, ranging from: CSS, Ajax, Javascript, web design, graphics, typography, advertising & much more. Our goal is to help you communicate effectively on the web with an engaging website or functional interface.