Related Posts for Jerome’s Keywords Plugin
When visitors find your website via search engines or other websites, they are often there for a reason and want to find out about a particular topic of interest.
Presenting a list of related posts to a given post makes life easier for your visitors by showing them other posts you have written on the subject. This increases the chance that a visitor will stick around browsing your blog, and is perfect for existing visitors to find out your past thoughts on a particular subject.
Purpose
This Plugin uses Jerome’s Keywords and presents related posts according to the tags (keywords) of the current post.
Only one MySQL query is needed for each post, so there should not be any performance issue when using this plugin.
Downloads
zip, 2.0k — works with Jerome’s Keywords Plugin Version 2.0 only
Download obsolete version, works with Jerome’s Keywords 1.9 only: jeromes-keywords-related-posts_1-3.zip (installation instruction are included in the zip file, the below instructions are for version 2.1 only)
Installation
The plugin can be installed in 3 easy steps:
- Download the plugin (see „Downloads“ above).
- Decompress the .zip archive and put the file jeromes-keywords-related-posts.php into your plugins directory (/wp-content/plugins/) or into a sub directory of the plugins directory.
- Enable the plugin in the WordPress Plugins admin page.
Please note that you need to have Jerome’s Keywords plugin installed as well. The current version supports the new Keywords 2.0 Beta only, however you can also download an obsolete plugin version above.
Usage
Open the appropriate file of your theme to add the related posts, in most cases it is the file single.php or index.php in your theme folder.
Add the following code to the section where you want the related posts to be displayed:
<?php
if( class_exists('JeromesKeywords') and function_exists('jkeywords_related_posts') ) {
$relatedposts = jkeywords_related_posts();
if (!$relatedposts) {
echo '<p>No related posts</p>';
} else {
echo '<div class="related-posts">
<h3>Related posts:</h3><ul>' . $relatedposts . '</ul>
</div> <!-- [related-posts] -->';
}
}
?>
Options
Syntax of the plugin’s function:
function jkeywords_related_posts(
$order = 'DATE_DESC',
$limit_quantity = 5,
$limit_days = 365,
$format = '<li>%date%: <a href="%permalink%" title="%title%">%title%</a> (%commentcount%)</li>',
$dateformat = 'd.m.y'
) {
Parameters:
- $order: DATE_DESC sorts the related posts by post date, descending, DATE_ASC sorts by date and ascending, RANDOM displays the posts in a random order
- $limit_quantity: max. number of related posts to be displayed
- $limit_days: max. number of days to be considered, 365 means that related posts of the past 365 days are being considered.
- $format: the format of the output, you can apply the following placeholders:
- %date%: date of post
- %permalink%: the post’s permalink
- %title%: the post’s title
- %commentcount%: number of comments
- $dateformat: format of the post’s date %date%, see PHP: date – Manual for details
Version History and Changelog
- 2.1 [2006-11-29]:
Bug fix: Related posts that are scheduled for the future are no longer being displayed in the related posts list. - 2.0 [2006-11-26]:
New support: Now the new Jerome’s Keywords Plugin version 2.0 Beta is being supported.
New feature: Added $format flag for (almost) unlimited possibilites of formatting the output incl. date, comment count, etc. - 1.3 [2006-05-26]:
Bug fix: Special characters in the tags could not be used. - 1.2 [2006-03-21]:
New option: random order - 1.1 [2006-03-18]:
Added URL to plugin’s page. - 1.0 [2006-03-18]:
Initial release.