code > Yet Another Related Posts Plugin
by mitcho (Michael 芳貴 Erlewine). If you appreciate this plugin, please consider donating to the author.
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. YARPP is based on the work of Peter Bowyer, Alexander Malov, and Mike Lu. Key features include:
- 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!
- Related posts and pages: New in 1.1! Puts you in control of pulling up related posts, pages, or both.
- Simple installation: New in 1.5! Automatically displays related posts after content on single entry pages without any theme tinkering.
- Miscellany: a nicer options screen, 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
With 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.
Manual installation
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() 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.
FAQ
Every page just says “no related posts”! What’s up with that?
Most likely you have “no related posts” right now as the default “match threshold” is too high. Here’s what I recommend to find an appropriate match threshold: first, lower your match threshold in the YARPP prefs to something ridiculously low, like 1 or 0.5. Make sure the last option “show admins the match scores” is on. Most likely the really low threshold will pull up many posts that aren’t actually related (false positives), so look at some of your posts’ related posts and their match scores. This will help you find an appropriate threshold. You want it lower than what you have now, but high enough so it doesn’t have many false positives.
Why doesn’t YARPP use tags to find related posts?
YARPP currently doesn’t use tags to compare posts—it uses the actual content of the posts. Tag comparison as part of the “relatedness algorithm” will come soon but, in the mean time, I’ve found the current algorithm to work very well for many situations.
Ask your own question
Ask your own question on the wordpress.org forums.
Coming soon
- 2.0
- Tags and categories in the algorithm: by frequent request.
- RSS feed support: an option to automagically show related posts in RSS feeds, by request.
- Date and comment count in excerpt, by request
- Bugfix: an excerpt length bug
- Ordering results by date, by request
- User-defineable stopwords, especially to support other languages, by request
- Exclusion of certain pages/posts, by request
Version log
- 1.0
- Initial upload
- 1.0.1
- Bugfix: 1.0 assumed you had Markdown installed
- 1.1
- Related pages support!
- Also, uses
apply_filtersto apply whatever content text transformation you use (Wikipedia link, Markdown, etc.) before computing similarity.
- 1.5
- Simple installation: automatic display of a basic related posts install
- code and variable cleanup
- FAQ in the documentation
- 1.5.1
- Bugfix: standardized directory references to
yet-another-related-posts-plugin
- Bugfix: standardized directory references to