Looking for a way to feature some of your better posts? Here’s a method I’ve been using for a few months (visible on the index and the screencap to the right).
The five most recent posts that I’ve marked as “Featured” will appear in the list, along with a “view all” option that takes the clicker to a custom date-based archive.
How does it work? It’s done with multiple loops and categories.
Creating the Sidebar List
- Create a new category called “Featured.” Note its ID (mine is 72, so I’ll use that throughout this tutorial).
- Add a few posts to the category.
- Paste the following code into your sidebar, where you want the list to appear.
<ul>
<?php
$postslist = get_posts('category=72&order=DESC&numberposts=5');
foreach ($postslist as $post) :
setup_postdata($post);
?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php
endforeach;
?>
<li><a href="http://www.webmaster-source.com/featured/">[View All]</a></li>
</ul>
Be sure to replace the bold “72” with the ID of your category. Seeing as this is another loop, the code must be located below your main loop (which means your get_sidebar() command must be below the main loop in your template). If your template’s sidebar is in the wrong place, you could use the $wpdb->query() function. However, I will not provide pasteable code, as most themes’ sidebars are below the main loop (and it’s much better if it is, as your content will be higher up, which is better for search engines).
Creating a Custom Archive
Create a new file called featured.php. This will be your template for the archive. Upload it to your theme directory, after adding something like this into it:
<?php
/*
Template Name: Featured Posts
*/
?>
<?php get_header(); ?>
<div id="widecontent">
<h2>Featured Posts</h2>
<h3>2008</h3>
<ul>
<?php
query_posts('year=2008&category_name=Featured');
if (have_posts()) :
while (have_posts()) : the_post();
?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php
endwhile;
endif;
?>
</ul>
<h3>2007</h3>
<ul>
<?php
query_posts('year=2007&category_name=Featured');
if (have_posts()) :
while (have_posts()) : the_post();
?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php
endwhile;
endif;
?>
</ul>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You’ll have to modify it a little so it will work with your theme. Note that you have to add a loop for every year you have posts (every new year, you need to put a new one in).
Create a new Page (Admin->Write->Page) and call it “Featured Posts” (or something of the sort). Set the Post Slug to “featured” and the Template to “Featured Posts.”
Load yourdomain.com/featured/ into your browser to make sure everything works.
Note that this isn’t the only way to create the archive. You could just use the default, at yourdomain.com/category/featured/, or you could use $wpdb->query() to create a more advanced archive. It’s up to you, as well as your experience level. $wpdb->query() is generally the domain of plugin authors, and the large majority of bloggers should probably steer clear.
Well, enjoy your new Featured Posts system.
Pingback: Update: Double Your FeedBurner RSS Numbers Overnight | So You Want To Teach?
Pingback: DBT Group Project: Some Tutorials Worth Reading » Webmaster-Source
Pingback: Blog Writing Project: 5 Best Tutorials
Pingback: 4 tips to increase your Feed Readers (written by DailyBlogTips Writing Projects Participants) | JackBook.Com
Pingback: 4 tips to increase your Feed Readers (written by DailyBlogTips Writing Projects Participants) | JackBook.Com
Pingback: Blog Writing Project — Tutorials — Wayfarer Wings
Pingback: My 3 Favorite Tutorials From Daily Blog Tips
Pingback: My Picks for DBT's Jan Group Writing Project
Pingback: My top 5 picks from Daily Blog Tips Writing Project
Pingback: Os meus 5 melhores - Daily Blog Tips Writing Project - Blog do TioSolid
Pingback: Blog Writing Project: Tutorials » My top 5
Pingback: How to Write a Memoir to Remember Nominated for Best Tutorial
Pingback: Blog Writing Project: 71 Tutorials for Your Delight
Pingback: yhyif » Blog Archive » Blog Writing Project: 71 Tutorials for Your Delight
Pingback: Blog Writing Project: 71 Tutorials for Your Delight - DailyBlogTips.com