Yet Another Related Posts Plugin

Donate to mitcho (Michael Yoshitaka Erlewine) for this plugin via PayPal

by mitcho (Michael 芳貴 Erlewine) for WordPress.

Looking for a proven and innovative developer for your next web project? Why not check out my portfolio? I am available for hire.

NEWS: Follow YARPP on Twitter for news and updates!

relatedposts algorithm display disallowed disallowed

Description

Yet Another Related Posts Plugin (YARPP) gives you a list of posts and/or pages related to the current entry, introducing the reader to other relevant content on your site. Key features include:

  1. Limiting by a threshold: Peter Bowyer did the great work of making the algorithm use MySQL's fulltext search score to identify related posts. But it just displayed, for example, the top 5 most "relevant" entries, even if some of them weren't at all relevant. Now you can set a threshold limit for relevance, and you get more related posts if there are more related posts and less if there are less. Ha!
  2. Using tags and categories: New in 2.0! The new 2.0 algorithm uses tags and categories. The new options screen puts you in control of how these factors should be used.
  3. Related posts in RSS feeds: New in 2.1! Display related posts in your RSS and Atom feeds with custom display options.
  4. Disallowing certain tags or categories: New in 2.0! You can choose certain tags or categories as disallowed, meaning any page or post with such tags or categories will not be served up by the plugin.
  5. Related posts and pages: New in 1.1! Puts you in control of pulling up related posts, pages, or both.
  6. Simple installation: New in 1.5! Automatically displays related posts after content on single entry pages without any theme tinkering.
  7. Miscellany: a nicer options screen (including a sample display of the code that is produced New in 2.0), displaying the fulltext match score on output for admins, an option to allow related posts from the future, a couple bug fixes, etc.

Installation

Auto display on your website

Since YARPP 1.5, you can just put the yarpp directory in your /wp-content/plugins/ directory, activate the plugin, and you’re set! You’ll see related posts in single entry (permalink) pages. If all your pages say “no related posts,” see the FAQ.

Auto display in your feeds

Since YARPP 2.1, you can turn on the "display related posts in feeds" option to show related posts in your RSS and Atom feeds.

The "display related posts in feeds" option can be used regardless of whether you auto display them on your website (and vice versa).

Widget

Related posts can also be displayed as a widget. Go to the Design > Widgets options page and add the Related Posts widget. The widget will only be displayed on single entry (permalink) pages. The widget can be used even if the “auto display” option is turned off.

Manual installation

This is an advanced feature for those comfortable with PHP. 97% of users will be better served by the auto display options above.

If you would like to put the related posts display in another part of your theme, or display them in pages other than single entry pages, turn off “auto display” in the YARPP Options, then drop related_posts(), related_pages(), or related_entries() (see below) in your WP loop. Change any options in the Related Posts (YARPP) Options pane in Admin > Plugins. See Examples in Other Notes for sample code you can drop into your theme.

There’re also related_posts_exist(), related_pages_exist(), and related_entries_exist() functions, which return a boolean as expected.

The related_ functions

By default, related_posts() gives you back posts only, related_pages() gives you pages, and there's related_entries() which gives you posts and pages. When the "cross-relate posts and pages" option is checked in the YARPP options panel, related_posts(), related_pages(), and related_entries() will give you exactly the same output.

The related functions can be used in conjunction to the regular "auto display" option.

Customizing the "related" functions

Since YARPP 2.1, you can specify some custom options for each instance of related_*(). The arguments are specified as a single array argument (related_*(array(key=>value, key=>value, ...))).

The available keys in version 2.1 are (roughly in the same order as in the options page): (NOTE: some options will be deprecated in the next revision in deference to a new template-based system of display customization.)

© 2006-2008 mitcho (Michael 芳貴 Erlewine).
Hosted at (mt) Media Temple.
The views expressed on these pages are mine alone and do not
reflect those of my employers and clients, past and present.