I find that I reference other posts on my blog all the time.  I always found it to be such a hassle because of URI information that had to be entered.  Then, since I use permalinks with the name of the post in the URI, I am always in danger of breaking myself if I ever decide I want to change the slug or the title.  The Cross-references WordPress plugin written by Fracesc Hervada-Sala solves this problem - and then some.

Overall Grade: A+
Plugin Name: Cross-references
Version: 1.2
Plugin URI: http://francesc.hervada.org/wordpress.html
Description: Insert cross-references between posts or pages with [cref ID], for example [cref 12], get all back references via template with <?php the_crossreferences() ?>. See the plugin homepage for the details.
Author: Francesc Hervada-Sala
Author URI: http://francesc.hervada.org/
Installation

Installation is very simple.  Just put it in your WordPress plugins directory and activate it.

Usage

There are two features this plugin provides - forward references and back references.

Forward References

You can refer to another post by its ID number, like this:

[cref ID]

where ID is the number of the post.  The title of that post will appear at that location as a hyperlink to the other post.  If you want to display text other than post title, add it aft the post ID:

[cref ID click here]

This will display the text "click here" as a hyperlink instead of the title of the post.  One last thing you can do with this syntax is indicate that you want another post to be displayed in the list of related posts whether they refer to you or not.

This will add both posts to each other’s list of related posts and will not display anything in the current post at that position.

Backward References

To show a list of all the posts that link to the current post, put <?php the_crossreferences() ?> in a page or post template.  Of course, if you want to allow for the plugin to be deactivated, you should specify this instead:

<?php if(function_exists('the_crossreferences')) { the_crossreferences(); } ?>

The the_crossreferences() function takes up to 4 parameters:

  • $before - Optional.  The string to be inserted once before the related posts lists only if there are any.  The default value is <li>.
  • $between - Optional.  The string to be inserted between two entries in the list.  The default value is </li><li>.
  • $after - Optional.  The string to be inserted after the related posts lists only if there are any.  The default value is <li>.
  • $id - Optional.  The ID of the post to for which to show related posts.  The default value is the current post.

The plugin homepage has some good examples for displaying cross references.  I chose to do this:

<?php
if (function_exists(‘the_crossreferences’))
{
    the_crossreferences(‘<h5>Related Posts</h5><ul><li>’, ‘</li><li>’, ‘</li></ul>’);
}
?>

This displays related posts, if any, in an unordered list, one per list item, with "Related Posts" as a header.

Conclusion

This plugin has really simplified the maintenance of referencing other posts for me.  I am much more comfortable changing titles now than I was before since I know my posts will reflect those changes.  Using IDs isn’t ideal, since I now have to find the ID of the post I’m interested in, but it’s a lot simpler than entering the post URI and the keeping the title in sync.  It also simplifies displaying a list of backward references.  The first version I tried had quite a bit of trouble.  This version works well with both WP 2.2.3 and 2.3.