Random Featured Post Plugin
Download from WordPress.org
The Featured Post plugin allows you to display a random post from a designated category. Ideally this should draw readers landing on your homepage to some of your best posts. The featured post will display the title ‘Featured Post’ (customizable) along with the post’s title, an excerpt and a link to continue to the full post.
This plugin requires Wordpress version 2.3 or higher and has been tested up to version 2.5.1.
Installation
- Download and unzip featuredpost.zip (see below) to your plugin folder.
- Activate the plugin from the Plugins section of your dashboard.
- (Optional) Create a ‘Featured’ category.
- Go to the ‘Featured Post’ options in your dashboard and select the categories from which you would like posts to be randomly selected.
- Check the ‘Show Featured Post’ box and click ‘Update’ to save your changes.
- Place a call to the show_featured_post() function in your template, most likely in your main index template just before the loop. See additional notes below.
Additional Notes
- The show_featured_post($PreFeature = ”, $PostFeature = ”, $AlwaysShow = false, $categoryID = 0) function has five optional arguments. The first two are for any HTML you would like to display before and after the featured post. The third argument is a boolean (true/false) argument which will override the ‘Show Featured Post’ option and always display the featured post when true. The fourth option allows you to specify a category to display from, overriding the selection in settings page.
- If you choose to display excerpts, the plugin will display your optional custom excerpt from the advanced options section of your post; otherwise, the standard Wordpress excerpt is shown. The fifth option allows you to show more than one post at a time, overriding the settings page option.
- This plugin respects the <!–more–> tag when you choose to display the full content. There is a setting which allows you to ignore the tag and display the full post.
Examples
-
This example will display the featured post only on your homepage inside a span block:
if ( function_exists('show_featured_post') ) if (is_home() && !is_paged()) show_featured_post('<span class="container">','</div>'); - This example will always display the featured post, ignoring the ‘Show Featured Post’ option and the category ID option in settings:
if ( function_exists('show_featured_post') ) show_featured_post('', '', true, 42); - All output is contained in a DIV class named “featuredpost” and can be adjusted via your stylesheet.
Change Log
v1.1.3 (May 15, 2008)
- Bug fix: more tag was not being respected on single posts/pages when full content option was selected.
v1.1.2 (May 5, 2008)
- Added option of showing posts and/or static pages.
v1.1.1 (April 30, 2008)
- Added multiple category selection option.
- Added option to display multiple posts.
v1.1.0 (April 28, 2008)
- Discontinued use of truncated post content and switched to the option of displaying full post content with HTML intact or standard excerpts, custom or Wordpress generated.
- Added option to ignore the <!–more–> tag when displaying full post content.
- Added fourth argument to show_featured_post() function to allow category ID from settings to be overridden.
v1.0.1 (April 11, 2008)
- Added category name and ID table to options page for convenience.
v1.0.0 (April 7, 2008)
- Initial plugin release.
Bugs/Feature Requests
You can leave a comment below or contact me at scott(at)mydollarplan(dot)com.
If you find this plugin beneficial, please consider donating for the author’s time. Any little bit is appreciated!
Download from WordPress.org









Great plugin and just what I’m looking for. Many thanks.
Unfortunately, as a relative newcomer to Wordpress and adjusting css style sheets, the additional notes and examples provided are a bit beyond me. Not quite sure where to place the code. Any chance of a more detailed step-by-step on how to do this?
Kate FoyApril 9th, 2008 at 3:20 am
Kate,
ScottI’m not very good with CSS either but here’s my best attempt at an explanation. In your Design-Theme Editor, open your stylesheet and create a section like this:
#content .featuredpost {
border:1px solid #000000;
}
You can further adjust other elements in the featured block, such as the post title, like this:
#content .featuredpost h2 {
color: #FF0000;
}
Does that help?
April 9th, 2008 at 9:42 am
I’ll give it a shot. Thanks Scott.
Kate FoyApril 9th, 2008 at 8:29 pm
Hi Scott
no go. This is what I have done:
downloaded, unzipped and uploaded the plug-in to my plug-ins folder; activated the plug-in on my WP Dashboard; inserted the category name for random post to choose from; saved. BTW, I assume Category ID is the name of the category? It’s not showing after I hit the save button.
I then inserted this code in the index.php within my theme folder:
<?php if ( function_exists(’show_featured_post’) )
if (is_home() && !is_paged())
show_featured_post(”,”);?>
And in my CSS style sheet for the theme, I’ve inserted:
#content .featuredpost {
border:1px solid #000000;
in the content styles section of the file.
I can only think I’ve got the code in the wrong place, either within the particular file or in a wrong file altogether.
Sorry to be a pain, but I’d really appreciate a solution as I’ve gone past the ‘forget it’ stage and want to make it work! Call me ornery …
Best
Kate FoyApril 9th, 2008 at 9:58 pm
Kate,
ScottThe category ID is a number, it won’t save if you enter text. In your dashboard go to Manage-Categories and click the category you want. Then look in the address box of your browser and you’ll see a cat_ID= at the end of the URL. The number at the end is what you want. Also, did you check the “Show Featured Post” box in the options? If you need more help just shoot me an email.
April 9th, 2008 at 10:30 pm
Is there a way in which you can put more control in this plugin? Such as the fact, that some users may not want a random post, but posts ordered in terms of the newest first..
NickApril 10th, 2008 at 12:11 am
Nick,
ScottDo you mean that you want to always display the single newest post from a specific category as your featured post? Or am I reading your comment wrong?
April 10th, 2008 at 9:05 am
Very interesting plugin. I’ll probably use this for some of my future theme developments.
@Nick: You can probably just use a wp_Query to do that.
Good luck!
LelandApril 10th, 2008 at 10:23 am
Ok Im a retard…. Could anyone do a step by step guide for this?? I mean down to the \”T\”… Sorry and thanks for all the help…
TimApril 10th, 2008 at 11:27 pm
This is the perfect plugin for me except I need to allow it to show images — any advice? I am trying to show a thumbnail that links to my latest project but right now I can only display text.
KristenApril 16th, 2008 at 11:07 am
@Kristen
The plugin shows the content of a post. I can put in an option to not strip HTML tags from the post content which would show images in your post, along with any text you might have as well though.
ScottApril 16th, 2008 at 11:25 am
That would be perfect. I tried examining the plugin code but couldn’t identify what exactly I needed to modify.
KristenApril 16th, 2008 at 11:49 am
@Kristen
Look for the lines
$desc = attribute_escape(strip_tags($post->post_excerpt));
and
$desc = attribute_escape(strip_tags($post->post_content));
and replace them with
$desc = attribute_escape($post->post_excerpt);
and
$desc = attribute_escape($post->post_content);
respectively.
ScottApril 16th, 2008 at 11:55 am
I modified the plugin as instructed and it nearly works — except instead of displaying the image you see <img src=”…..”
KristenApril 16th, 2008 at 12:22 pm
Sorry, forgot to take off the attribute_escape functions as well. The lines should be
$desc = $post->post_excerpt;
and
$desc = $post->post_content;
ScottApril 16th, 2008 at 12:34 pm
Thanks a million, it definitely works now!
KristenApril 16th, 2008 at 1:01 pm
Great plug-in, thanks. I’m using the following classes in my stylesheet, which work well for me:
h3.featuredpost
h2.featuredpost a
AndrewApril 16th, 2008 at 10:55 pm
this actually works a bit better though after tinkering:
div.featuredpost h2 a
div.featuredpost h3
AndrewApril 17th, 2008 at 1:16 pm
Hi, thanks a lot for this great plugin. I like it very much and you can see it in action on my site.
Some questions:
I would like to use the more-tag including images instead of truncating the text. Is that possible or do you plan this feature?
The solution in comment 15 breaks the formattings when attributes like strong or italic are used? Is it possible only to use the img-tag inside the truncated text?
Best wishes and excuse my chaotic english.
Daniel
DanielApril 22nd, 2008 at 9:26 am
another question is, if it possible to use this as a widget?
DanielApril 22nd, 2008 at 9:30 am
@Daniel,
Widgetizing this plugin is not possible; however, there are other plugins out there for displaying featured posts in your sidebar if that’s what you would like to do. Check the Wordpress.org plugin database. I’ll take a look at your other feature requests when I have a chance.
Also, if anyone is just looking for a plugin to display a single featured post and is not interested in randomizing from a group of posts then I would recommend using the WP-Sticky plugin.
ScottApril 22nd, 2008 at 9:39 am
Hi Scott,
yes I wanted to show your random featured post in a sidebar, because I like the flexibility to manage a group of articles through the categories, which are important for me
It would be really great to use an eyecatcher too.
DanielApril 22nd, 2008 at 10:11 am
I’m not a coder, but this worked for me:
$desc = strip_tags(($post->post_excerpt), ”);
DanielApril 22nd, 2008 at 10:54 am
Hi Scott,
Thanks for sharing with us this plugin. It works well in our site ~ with truncated text, etc.
Because I wanted to display the entire text of the post being rotated, I increased the character limit in the admin option which works okay except all the html tags and formats are lost.
Is there a way I could display the entire text of the post being rotated with formatting being retained?
Thanks heaps.
PamPam
April 26th, 2008 at 6:50 pm
Hi- I’ve added this plugin to my site and it works great, but how do I set it to show more than one featured post at I time? For now I’ve duplicated the code: , but more than often it shows the same featured posts in a row.
CaseyApril 26th, 2008 at 8:57 pm
@Pam:
I’ll really try to fit in some time to work on the plugin this week. In the meantime, comment 15 will do what you’re looking for, but keep in mind that if the post is ever truncated in the middle of a tag it will mess up your formatting.
@Casey:
ScottThis plugin is really designed to only show one featured post at a time but I’ll see about adding an optional parameter to the function call so that you can specify different categories for each call, that should help you out.
April 27th, 2008 at 9:07 pm
Ok Scott thanks! I only need to specify one category - but I’d just like to show more than one Featured Post at a time. Let me know if you find a way to make that work - thank so much!
CaseyApril 28th, 2008 at 6:34 am
The plugin has been updated with a few new options. Basically, the truncated post option has been discontinued in favor of displaying either full, formatted post content (with or without more tag) or post excerpts.
@Casey:
ScottThe best I could do for you is add an additional option to the function call to specify the category (see above for example). You’ll be able to have two featured posts at once but they will have to be from different categories. You can have them come from the same category by creating two new categories just for featured posts and then adding different posts to each of those categories, along with their original categories.
April 28th, 2008 at 2:07 pm
Thanks very much, Scott. You’re a legend!
The admin option to use “excerpt” or “full text” with formatting remaining intact is just exactly what I’ve been looking for.
PamApril 28th, 2008 at 3:22 pm
Its possible to configure more than just one category?
MiguelApril 30th, 2008 at 2:02 am
@Miguel:
That’s one of the things on my “to do” list for this plugin.
ScottApril 30th, 2008 at 8:39 am
Plugin has been updated with multiple category selection and multiple post options.
ScottApril 30th, 2008 at 1:31 pm
Wow, thats was fast… thanks for the wonderful plugin, I am using and will update.
MiguelApril 30th, 2008 at 8:17 pm
Hi - really useful plugin with one problem which means I can’t use it. I’ve just noticed that it displayed one of my ‘pages’ instead of one of my ‘posts’, even though pages don’t fall into any of the categories - is it possible to exclude ‘pages’?
PaulMay 4th, 2008 at 9:13 am
@Paul:
Good catch. The plugin has been updated with the option of displaying posts and/or static pages.
ScottMay 5th, 2008 at 10:53 am
Sounds good, and I would like to try this plugin but after bouncing back and forth between this page and the Wordpress plugin page I cannot find it.
Where is it?
DigitalZipMay 5th, 2008 at 1:14 pm
@DigitalZip:
The link is at the top (I just added) and bottom of this page. It takes you to the WordPress.org Plugin Directory where you can find the download link on the right side of the page in an orange box.
ScottMay 5th, 2008 at 1:20 pm
Thank you Scott. It’s not very obvious on Wordpress that you should click on the orange download box. Well it isn’t to me
Got it now anyway.
DigitalZipMay 5th, 2008 at 1:27 pm
Hi Scott
I was the first commenter here and just wanted to say thanks for your neat plug-in and for being such a responsive developer. It’s really appreciated especially by those of us who are ‘challenged’ by all this coding stuff!
I’m part of the comment08 challenge running right now to increase communication round the blogosphere, and thought I should say thanks to people who make my blogging life much easier. You’re on my list!
Best wishes.
Kate FoyMay 5th, 2008 at 4:29 pm
Wow, that was quick! Since my comment I have been dabbling with using multiple loops within Wordpress, and found that this is also a good way to display a single random post alongside my usual homepage content. I’ll use that route in the interests of keeping plugins to a minimum, but this is certainly useful for those who don’t want to delve into advanced stuff like multiple loops.
PaulMay 5th, 2008 at 5:20 pm
Thanks Scott. Given the series of improvements that you have introduced to your plugin, I guess comment #24 has helped it realize its full potential, that there’s a big community out there looking for this kind of plugin. Good work! ~ Pam
PamMay 6th, 2008 at 5:22 pm
Glad to see others are finding this useful.
Spread the word!
ScottMay 6th, 2008 at 9:09 pm
hi. Thanks for plugin
perfect.
regards
baronMay 11th, 2008 at 11:55 am
Hi Scott,
I wanted to add this code into single.php to showw my featured articles in top of each post.
On my Homepage it works fine but in single.php it always displays the full post?
Best wishes
Daniel
DanielMay 12th, 2008 at 1:01 pm
@Daniel:
Are you using the most recent version of the plugin? I’m unable to replicate the problem you’re having. Please check your settings and make sure you’ve selected “display excerpt” under the content options.
ScottMay 13th, 2008 at 9:18 am
Hi, Scott.
Thanks for a great plugin. I’ve got it working pretty well.
I’d like to see the date of the featured post show up with the post and excerpt. Could you help me with the code for that?
Thanks!
WardehMay 13th, 2008 at 9:35 am
@Wardeh:
I thought about including the date but decided against it because typically a “featured” post would be an older post from deep in your archives and highlighting the date might keep readers from clicking through, or at least that was my thinking.
If you want to add the date you’ll need to modify the code. Look towards the end of the show_featured_post function and in the place of your choosing insert the line
Scottecho date(”F n,Y”,strtotime($thepost->post_date));
May 13th, 2008 at 1:09 pm
Hi Scott,
I use 2.3.3 and K2. The problem is, that the same functions has different results. On my homepage everything works fine, but in single.php I got the whole article.
No, I use full content with “more-tag”. If I switch to “excerpt” everything works fine.
DanielMay 15th, 2008 at 1:29 am
@Daniel:
I hadn’t tried the full content option with the more tag on a single post. I found the bug and the plugin has been updated. Thanks for bringing it to my attention.
ScottMay 15th, 2008 at 11:15 am
hi scott, thanks a lot. hope your private million dollar plan works
but there is another mysterious behaviour. on the homepage it works again fine, but now after the more tag, only on single page, I get the list of related articles inside it?
DanielMay 15th, 2008 at 12:32 pm
@Daniel:
I’m guessing this is because whatever plugin you are using to generate the related articles is hooking the function that displays the formatted content. I’m not sure how to get around this. What plugin do you use for related articles?
ScottMay 15th, 2008 at 1:14 pm
hi scott, I use simple tags: http://wordpress.org/extend/plugins/simple-tags
DanielMay 15th, 2008 at 2:10 pm
@Daniel:
I just glanced at the code for that plugin and I’m near certain that’s the issue. You can probably test it by disabling that plugin. I’m not sure how to get around that, but I’ll do some thinking and let you know if I figure it out.
ScottMay 15th, 2008 at 2:16 pm
You’re right. When I disable the plugin everything works fine, as it should.
It’s a pitty, because I like simple-tags for managing the tags very much. Hope you find a solution.
DanielMay 16th, 2008 at 4:54 am
but for the moment I decided to disable the related posts, because your way of featuring articles is much more attractive.
DanielMay 16th, 2008 at 9:28 am
@Daniel:
I’m glad you find the plugin so useful. Until I can find a fix, you might want to check out another plugin to do the related posts. We use Similar Posts here and I’m happy with the way it works.
ScottMay 16th, 2008 at 9:31 am
I’ve successfully done steps 1-5 but 6 is where I get confused… what does it mean to place a call? and what is a loop… What exact code should I be placing in my index.php per theme??
LinzMay 16th, 2008 at 12:09 pm
@Linz:
In index.php look for the line that has “while (have_posts())” in it; that’s the start of the loop. Just before that line place the code from the first example above, making sure to include it between the “” tags.
ScottMay 16th, 2008 at 1:15 pm
Great plugin. Anyway, can it be inserted into the page/page?
Thx
gofreeMay 16th, 2008 at 1:35 pm
@gofree:
Yes, but if you read the other comments you’ll see that it may conflict with some plugins.
ScottMay 16th, 2008 at 1:46 pm
Hi Scott,
I am trying to call it using this show_featured_post() with Adman plugin to have the featured post appear on the top of index in homepage, but it seems not working as it shows the code show_featured_post() back.
Did I do sth. wrong.
Thanks
gofreeMay 16th, 2008 at 11:14 pm
@Scott. Great tipp. Thanks again.
DanielMay 17th, 2008 at 2:27 am