Two ways to get the job done.
One of the features I included in my personal WordPress-based site (www.marialanger.com) is a listing of the 20 most recent posts. You can find this list in the sidebar of the Home page.
I created this list with the following code in the sidebar.php template file:
<?php wp_get_archives('type=postbypost&limit=20'); ?>
The type parameter tells WordPress to show individual posts. The limit parameter tells WordPress how many posts to display. You can set this number to anything you like.
I wanted to include this same feature on wickenburg-az.com, a site I maintain with information about the town I live in, Wickenburg, AZ. Unfortunately, that site makes full use of the Event Calendar plugin to display a list of upcoming events in the sidebar. Although the plugin is configured so events to not display on the Home page, it’s impossible to prevent recent event titles from being included when using the wp_get_archives tag — there’s no exclude parameter. And since clicking one of those titles would display a very boring two-line description of the event, I didn’t want those titles included in the list of recent posts.
What’s the solution? Well, I already had the Customizable Post Listings plugin installed on wickenburg-az.com. This plugin offers flexible ways to list posts in the sidebar. All I had to do was figure out the parameters to include all categories except the one set aside for Event Calendar.
I fiddled around with it a bit and came up with this:
<?php c2c_get_recent_posts (15,"<li>%post_URL%</li>",'1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24','date','DESC'); ?>
The numbers in the code is a space-separated list of all the categories I wanted to include. I was lazy and just listed all category numbers between the first value (1) and the last (24) even though other values in between are skipped in my category list. Notice that 11 is missing. That’s the category number for the Upcoming Events category used by Event Calendar.
The result was the list I wanted. You can see it in the sidebar of the Home page at wickenburg-az.com.
Technorati Tags: category, howto, list, plugin, blog, WordPress












