Skip to content

Featured Content For WordPress

It’s surprisingly easy to build a neat little featured content area in WordPress, using a custom query to grab a couple of posts from a selected category, tag or even custom field. In this post we’ll find out how to build a simple featured content area for your blog, rather like the one I recently added to WPShout:

Choose your posts

First thing you need to do is choose which posts you want to have in your featured area. For argument’s sake, I’m going to use a category “featured”. We’re going to be building something like what’s currently on WPShout: no fancy jQuery, just something smart and functional that clearly shows off a couple of posts. Because we’re showing only three posts, we’re not going to do the usual and display the three most recent posts, but be bold and randomly pick three posts out of our category “featured”. This requires a custom query looking something like this:

    $featured = new WP_Query();
<?php while ($featured->have_posts()) : $featured->the_post(); ?>

<?php endwhile; ?>
Using a custom query here means we don’t interfere with the standard loop which you’ll (presumably) run afterwards.

Displaying posts

Now that we’ve got our posts, we need to display them. We’ll wrap them in a div with the titles wrapped in H2s and linked up, followed by the post’s excerpt. That’ll all end up something like this:

<div class="featured-post">
	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
	<?php the_excerpt(); ?>
</div><!-- .featured-post -->

Of course, we’ll then need to sandwich that in our query, so we end up with the following:

    $featured = new WP_Query();
<?php while ($featured->have_posts()) : $featured->the_post(); ?>

<div class="featured-post">
	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
	<?php the_excerpt(); ?>
</div><!-- .featured-post -->

<?php endwhile; ?>
By adding the div within the loop, this runs it for every post so that each post is wrapped in the class featured-post.

Next a little styling. Nettus recently published a screencast showing how to make the fold over (that’s actually a triangle) effect purely with CSS. We’ll be using that technique here to give a little pop to our featured content. We’ll also be employing some subtle CSS3 shadows and gradients to subtly make our content look awesome.

First, we need to wrap the whole lot in a div and give that a width, background etc:

#welcome{ position:relative; margin:0; background: #EAEAEA;
height:180px; padding:20px 20px 20px 40px; width:662px;
text-shadow:1px 1px 1px #fff; margin:0 0 0 -20px;
-webkit-box-shadow: 1px 1px 3px #292929;
-moz-box-shadow: 1px 1px 3px #292929; }

In addition to the CSS3 box shadow we’ve got, you might like to add some CSS3 gradients to the box, something like this looks subtly awesome!

background: -webkit-gradient(linear,left top,left bottom,from(#fff),to(#C9C9C9),color-stop(1,#C9C9C9)) fixed no-repeat 0 100%;
background: -moz-linear-gradient(100% 100% 90deg, #C9C9C9, #FFF) fixed no-repeat 0 100%;

We can then add a little styling to the .welcome-post class we created to wrap each post with:

.welcome-post { width:200px; padding:0 20px 0 0; float:left;}

This’ll split up the area into three little columns, one for each post.

We can then style links and H2s:

#welcome h2{ font-family:arial; border-bottom:dashed 1px #aaa; padding: 0 0 10px; }
#welcome a:hover{ color:#444; }

And again, some optional CSS3 enhancement:

#welcome a{ -webkit-transition: all 0.2s ease-in-out; -moz-transition: all 0.2s ease-in-out; }

Finally, we just need to add the little arrow:

.arrow { border-left: 20px solid transparent;
border-top: 10px solid #3E8AAD; height: 0px; left: 0px;
line-height: 0; position: absolute; top: 221px; width: 0px; }

And we’ve created an awesome featured content area. You can grab the source files below and just check out the homepage for an example.

[button href=]Download[/button]

Yay! πŸŽ‰ You made it to the end of the article!
Alex Denning

Most Voted
Newest Oldest
Inline Feedbacks
View all comments
June 9, 2010 1:57 am

I’m using Custom Taxonomies (as opposed to categories) to organise a site. I use Stickies to feature posts (as it seems a reasonably-simply solution). However I want my sticky/feature posts to appear at the top of EVERY page (all taxonomies – regardless).

Apart from manually assigning each sticky post to every taxonomy, is there some way to achieve this?

May 31, 2010 6:43 pm

Why do you use postion relative twice πŸ™‚ ?

June 3, 2010 3:13 pm
Reply to  Alex Denning

I tried it but didn’t notice that too! Not until I read Furuskog’s comment. πŸ™‚

Best On WordPress From The Past Week N.8 Β» wpCanyon
May 31, 2010 9:32 am

[…] Build A WordPress Powered Featured Content Area […]

May 25, 2010 12:42 pm

I saw the added intro box in the homepage last week, noticed that you didn’t use any image, just pure CSS. Was tad shy to ask how you did it, but here it is now, complete with source files! πŸ™‚

Downloaded and tested it already, works perfectly! I just changed the “featured-post” class to “welcome-post”.

Thanks a lot for sharing!

Scott Corgan
May 24, 2010 4:38 pm

Yes, yes! WordPress to the rescue. Thanks for the heads up in this technique. Looking to get more traffic, this could be a solution!

Dave Redfern
May 24, 2010 2:53 pm


Nice tutorial although I would suggest not creating a category for featured and instead using the commonly unused sticky feature built into WordPress. This is much more logical for both the content and structure of WordPress.

Just assign a post to sticky and then change the query to.

$featured->query('posts_per_page=3&post__in=' . get_option('sticky_posts') . ',


May 25, 2010 3:57 pm
Reply to  Alex Denning

Actually, I agree with you re: sticky. I would actually use a tag as opposed to a category myself, but as you noted, you used a category simply for the sake of this tut.

June 7, 2010 1:56 am
Reply to  John

Actually you can make the thumbnail function better by restricting the width to the same size as .welcome-post


9999 stands for any random height.

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!

Would love your thoughts, please comment.x

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

20 Best Free WordPress Themes for 2024 (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...