Set up a testimonials category — no need for a plugin.
There are a couple of plugins designed specifically for testimonials, but I didn’t want to use them; they use their own databases, and don’t keep with WordPress’ simplicity. If possible, the best way to work with WordPress is to use it’s built-in functionality.
I also wanted to have the testimonials as a category in WP, rather than as a separate plugin. This code will work for any type of category, not just a testimonial.
Here’s how to create a random post item in your sidebar:
-
Create a Testimonials Category
I created a category for testimonials. In this example, the category ID is 3
-
Create the Query
query_posts('showposts=1&cat=3&orderby=rand');Let’s break down what is going on in the code above:
- Request one result (
showposts=1) - Define the category ID for testimonials (
cat=3) - Randomize the result (
orderby=rand)
- Request one result (
-
Display the testimonial
<li class="widget"> <h2>Testimonials</h2> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h3><?php the_title() ?></h3> <?php the_excerpt() ?> <?php endwhile; endif; ?> </li> <?php wp_reset_query(); ?>
With the simple code above, you can add testimonials to your WordPress website as a basic category, and have a random testimonial displayed in your sidebar.
To take it one step further, you can create a Testimonials template page, and have it as a static page on your website by simply having query_posts('cat=3).
Use Advanced Category Excluder
You can exclude the testimonials category from your sidebar category widget and many other places on the site without having to tear up your theme and add a lot of custom code. Simply download and install the Advanced Cagtegory Excluder (ACE) plugin for WordPress.
Note: I updated this post to be more relevant and simple. The original post was on 2/21/2008.

Pingback: Links for 8th October 2008 | Velcro City Tourist Board
Pingback: WordPressハッカーズ