Out of the box, the way to sort items in WordPress is to affect the…
I’d say there are a good amount of related posts WordPress plugins out there, and sometimes it can be hard to sift through. A lot of it depends on your specific needs, as things range from more or less automatic to intricately customizable. Contextual Related Posts sits somewhere in the middle. It gives you a good amount of control over which related posts to show, but automatically appends them to the bottom of your content.
What’s It Do?
Contextual Related Posts will create a list of related posts to display at the bottom of your page content. It figures out what these posts should be by using the current post’s title and content, so posts are linked by something stronger then tags or categories. Related posts are automatically appended to the end of a page (unless you turn the feature off) and offer a number of options for customizing the output of the plugin on each post.
You also have control over caching, thumbnail support, what posts, categories, or post types to exclude from the lists, and styles. If you need to specify when to include related posts on a more limited basis, there also options to either uses a shortcode or function to include the list wherever you would like in your theme.
How’s It Work?
Activating the plugin will automatically generate a list of related posts and include them on the bottom of each post. By default, this will only happen on Posts and Feeds, not on your WordPress Pages, and each list will include 5 posts. Related posts will be output in a standard unordered list, but you can customize the styling later.
To customize the plugin go to Settings -> Related Posts. The first tab that you are brought to is General Options. The first thing you will see is a checkbox labeled “Cache Output.” If you select this then related posts lists will be cached on your server, and only updated when a post is saved. Unless you have a very dynamic site where content changes often, I recommend checking this box. Next, there are text fields for “Number of related posts to display” and “Related posts should be newer than.” The default is 5 posts, newer than 1,095 days but these should be tailored to the needs of your blog.
The rest of the options on this page allow you to define which posts to include as related posts, and what post types should contain the lists. You can exclude entire categories, post types or even single posts, the latter by specifying post IDs. If you wish to exclude entire taxonomies, use the checkboxes for post types, and the text area for categories. The post type “attachment” is checked by default, but you will probably want to disable this option or media items may be displayed in your related posts. Finally, you’ll see the “Add related posts to” section. This allows you to specify which post types related posts should be added to, e.g. Posts, Pages, Category Archives, etc. If you want to control where related posts go manually instead of having the plugin insert them automatically, uncheck all of the boxes for now.
The next section is Output Options. This will define how related posts should be output. You can specify what title to attach to the top of the list, how much text of a post (such as excerpt or just the title) to include, and exclude display on certain posts.
After that are the “Post Thumbnail” options. By default, this will be switched off, but if you want to make use of it, you can specify where to include the thumbnail, it’s maxed height and width, and a default thumbnail, among a few other options. Keep in mind, these thumbnails will be completely unstyled at first, so they may look a little off. Luckily, there is an excellent tutorial on customizing the CSS of Contextual Related Posts to make it more consistent with the style of your theme.
The next tab, Feed Options only pertains to you if you have selected to include related posts on your WordPress Feeds in the General Options tab. This section gives you a little more control over what related posts to include when someone is looking at your post feed, say through RSS. You can change the number of related posts or chose to include a thumbnail with different dimensions than the default.
The last tab, Custom Styles, contains only a single text box. In there, you can enter in custom styles to change the look and feel of the outputted list. I’d recommend rolling these styles into your theme’s stylesheet, but if you are unable to do this, then these styles will simply be inserted into the <head> section of your page and will work just fine. For a full list of what CSS classes you can use to style the plugin’s output, visit the FAQ.
If you need even more control over exactly where related posts should go, and what pages they should go on, you also have the option to manually include them wherever you would like in your WordPress theme. If you chose to go this route, make sure to uncheck all of the post types in the “Add Related Posts to” section in General Options. The first way to include related posts is to use the [[crp]] shortcode anywhere in your post editor. This comes with two parameters, limit (integer) and heading (boolean). So, if you want to show 7 posts with no heading, you would use:
[[crp heading="0" limit="7"]]
The other way to include related posts is to use functions included with the plugin. The first is echo_ald_crp(). This will display the related posts in your theme’s files wherever you place the function instead of automatically displaying them. Just add this line of code to your desired php file (category.php, single.php, etc.).
<?php if(function_exists('echo_ald_crp')) echo_ald_crp(); ?>
There is also the function get_crp_posts(). This will retrieve a list of post IDs of related posts which you can then return however you would like, with two parameters, $postid, by default the current post, and $limit, the number of post IDs to retrieve. Each object in the outputted array will be the post ID of a related post. So if you have a limit of 7, you will get 7 objects, each with a key of “ID” and a value of a post ID. You can use this to output the data however you would like using standard WordPress functions like get_permalink. Don’t use this function unless you know what you are doing and you have some developer experience. You can look at the plugin code if you want a little more information about how this function works.
<?php $limit = '7' if(function_exists('get_crp_posts')) get_crp_posts($postid, $limit); ?>
Costs, Caveats, Etc.
Contextual Related Posts is free and updated with improvements fairly often. It appears that Ajay is still adding features, so it’s worth watching and using and if you need help, the best place to go is the WordPress forums.