View any single-post page from Mimbo Pro and you’ll notice two sidebar modules called “More from this category” and “More from this author”.
Why Is It Useful?
Pretend you’d discovered that story (“Kenya tourism, economy devastated by violence”) via random Google search. You might finish reading, know nothing else about the site, and hit your ‘Back’ button. As a designer, you want to help users explore topics in a forward or sideways motion from anywhere on the site. You can accomplish this by pulling in related content and providing logical jumping-off points, without requiring users to work backward.
Online newspapers like The Times use this principle. This article on Hillary Clinton is supported by smaller modules like political cartoons and related election coverage:
Politically-minded readers are now immersed in a topic they already enjoy, and are more likely to dig deeper into a whole section of the website rather than just one story. Good information-design connects the page to the interests of the user. Think of Pandora’s scrolling interface and the way it begins to ‘know’ your musical taste, compelling you to visit more often.
The Code
Here’s a simplified version of the code Ben wrote for Mimbo Pro, which must be included outside of the loop:
<?php
//Gets category and author info
global $wp_query;
$cats = get_the_category();
$postAuthor = $wp_query->post->post_author;
$tempQuery = $wp_query;
$currentId = $post->ID;
// related author posts
$newQuery = "posts_per_page=5&author=" . $authorPosts;
query_posts( $newQuery );
$authorPosts = "";
$count = 0;
if (have_posts()) {
while (have_posts()) {
$count++;
the_post();
if( $count<4 && $currentId!=$post->ID) {
$count++;
$authorPosts .= '<li><a href="' . get_permalink() . '">' . the_title( "", "", false ) . '</a></li>';
}
}
}
// related category posts
$catlist = "";
forEach( $cats as $c ) {
if( $catlist != "" ) { $catlist .= ","; }
$catlist .= $c->cat_ID;
}
$newQuery = "posts_per_page=5&cat=" . $catlist;
query_posts( $newQuery );
$categoryPosts = "";
$count = 0;
if (have_posts()) {
while (have_posts()) {
the_post();
if( $count<4 && $currentId!=$post->ID) {
$count++;
$categoryPosts .= '<li><a href="' . get_permalink() . '">' . the_title( "", "", false ) . '</a></li>';
}
}
}
$wp_query = $tempQuery;
?>
Then inside the loop, call the functions like this:
<h4>More from this category</h4> <ul> <?php echo $categoryPosts; ?> </ul> <h4>More from this author</h4> <ul> <?php echo $authorPosts; ?> </ul>
How’s it Work?
This whole task would be easy if we were pulling from a single static category or author. The query_posts function offers simple parameters. But pulling that information dynamically is slightly trickier.
Ben explains further:
All we need is work out which category/author the post is in and use that data to get the information. 5 posts are grabbed – then, when looping through the posts, we double check to make sure that the current post is not being linked to redundantly (this feature is not currently in Mimbo Pro but will be in the next update).
Because of the layout of the theme, we need to do all of this before the post is displayed. At the time I found the easiest method was to save the current page’s data as a new variable ($tempQuery = $wp_query;), do all the work, and then reassign the values so that the page can be updated as normal. This works great, but if I was to write it again I would use a new instance of the wp_query object, as described here by Ronald Huereca.
No matter how you code it, supporting your posts with related content is valuable to readers who want additional context and to bloggers who want a stickier site.


Pingback: WordPress Weekly Episode 20 | Jeffro2pt0
Pingback: WordPress Talk - June 15, 2008
Pingback: links for 2008-06-15 | JeremiahTolbert.com
Pingback: Related Category and Author Content in Wordpress | David Bisset: Web Designer, Coder, Wordpress Guru
Pingback: Cool coding tips from around your WordPress community - part 1 — WP Project
Pingback: Reasons for keeping your web portfolio short and sweet : Tracey Grady Design
Pingback: WordPress Weekend Resources - June 20, 2008 | Theme Lab
Pingback: stefanomavilio.com » Blog Archive » wordpress related categories
Pingback: Most Wanted WordPress Hacks: 11 New Requests (II) | Noupe
Pingback: Most Wanted WordPress Hacks: 11 New Requests (2) | virology.tv
Pingback: Wordpress Blog Services - Most Wanted WordPress Hacks: 11 New Requests (2)
Pingback: links for 2008-11-25 (Jarrett House North)
Pingback: Most Wanted WordPress Hacks: 11 New Requests (2) | SulVision
Pingback: Most Wanted WordPress Hacks: 11 New Requests (2) | Link Archive
Pingback: How to Display Related Category and Author Content - WordPress Forums
Pingback: 11个备用的WordPress编程技巧 - è èœåš
Pingback: HamzaED
Pingback: Sparkdog Better Findability » Blog Archive » test post 3
Pingback: Articulos relacionados por categoria y autor en WP | Codigo Geek
Pingback: 水煮网 » Blog Archive » 11个新WordPress技巧
Pingback: wordpress query posts标签函数8个高级使用-耕堂wordpress
Pingback: wp-query-post document
Pingback: [Blogs] Mostrar “contenido relacionado” a tus lectores = SEO + fidelización | Frikilife
Pingback: query_posts – WordPress テンプレートタグのリファレンス | Lovelog+*
Pingback: 20100505_wordpress_link « 不樂嗝
Pingback: [WordPress] 関連記事を表示 – カテゴリー、投稿者 - ハウスウエディング[665-667]
Pingback: 11个你应该知道的Wordpress技巧 - 刀客征途
Pingback: Mostrar "contenido relacionado" a tus lectores = SEO + fidelización | NeoSystm
Pingback: Managing Multiple Bloggers: Author Content Management on WordPress « Lorelle on WordPress
Pingback: Lorelle on WP: Managing Multiple Bloggers: Author Content Management on WordPress