Create a WordPress reader "explore" block to promote content

  • October 19th, 2008

Congrats. You have your own WordPress blog. Each passing day results in a handful of new unique readers. As your site continues to grow, convincing visitors to explore your site beyond your most recent posts becomes more of a challenge. Additionally, getting visitors – who happen upon older posts via search engines – to visit newer content is no small feat either. You can imagine the challenge of convincing both reader types to check out the rest of the content between your oldest and most recent posts.

Without going into detail concerning elements that your site should have, let’s look at one element that all blogs can leverage for increased page views. How do you get readers to explore content beyond their current view? By including a simple block element that introduces content before / after the current post, or articles deep within the archives. What is this simple block element comprised of?

  • Previous post – reverse chronological (if one exists)
  • Next post – chronological (if one exists)
  • Posts sharing the same categories
  • Posts with similar tags

If you browse the WordPress codex, or explore the individual files inside the default theme each installation includes, you’ll notice all of the required functions needed to create a simple "explore" – similar to what I have implemented on It really is just a matter of collection the functions, adding a little semantic markup, and styling to taste. The functions necessary are:

	<?php previous_post_link('%link') ?>

Codex: Used on single post permalink pages, this template tag displays a link to the previous post which exists in chronological order from the current post.

	<?php next_post_link('%link') ?>

Codex: Used on single post permalink pages, this template tag displays a link to the next post which exists in chronological order from the current post.

	<?php the_category(', ') ?>

Codex: Displays a link to the category or categories a post belongs to. This tag must be used within The Loop.

	<?php the_tags( '', ', ', ''); ?>

Codex: First available with WordPress Version 2.3, this template tag displays a link to the tag or tags a post belongs to. If no tags are associated with the current entry, the associated category is displayed instead. This tag should be used within The Loop.

Put it all together

Four simple functions placed together create an invaluable resource for readers to explore your archived content from various slices.

	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
	<ul class="exploreThese">
		<li>Previous: <?php previous_post_link('%link') ?></li>
		<?php /* if next post exists */ next_post_link('<li>Next: %link</li>'); ?>
		<li>Category: <?php the_category(', ') ?></li>
		<li>Tag: <?php the_tags( '', ', ', ''); ?></li>
	<?php endwhile; else: endif; ?>

The markup above generates an unstyled unordered list which when rendered provides:

Unstyled explore links

  • Line 1 & 8: Standard WordPress loop – required if you are re-using this code outside of the standard loop in single.php.
  • Line 3: Title (link) of a previous post.
  • Line 4: Title (link) of the next post. If there are no newer posts, the entire line is ignored. Thanks Ronald.
  • Line 5: Renders assigned categories (comma separated). Links to an archive page for posts sharing the same category.
  • Line 6: Renders assigned tags (comma separated). Each tag links to an archive page for posts sharing the same tags.

Drop the block of code somewhere inside single.php so that WordPress knows to generate the proper links. Note that if you do plan on inserting the code outside of the standard loop, lines 1 & 8 are required.

Expand on the explore block

Looking for more options to offer your readers? Check out some of these functions and plugins to add to the explore block: wp_dropdown_categories, wp_get_archives, wp_tag_cloud, Related Posts, or Random Redirect. Hopefully there is enough to expand on the idea of the reader explore block on your own. Feel free to drop any questions in the comments. [Digg this]