WordPress.org

Ready to get started?Download WordPress

Plugin Directory

!This plugin hasn't been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

Cross-references

Insert cross-references between posts and pages easily and get a list of backward references on each post and page automatically.

Related Posts List Styles

The related posts list can be formatted via CSS style sheet applying format to DIV elements of class "crossreferences".

Examples:

Place this at your theme's style.css file in order to get a light grey background color for the list.

    div.crossreferences { background-color:#f0f0f0; }

Put this to get green linked posts.

    div.crossreferences a { color:green; }

Template Funtions

Funtion `the_crossreferences`

You can place this function at your templates, in order to get the related posts list for a particular post or page. You do not need to use this, because the plugin shows the list automatically, but this function gives you a greater control on the appearance and the position of the list. If you use this function, please set up "Do not show related posts list" at the admin panel / Settings / Cross-references. Otherwise the related posts list will appear twice.

the_crossreferences($before,$between,$after,$id,$emptylist)

 $before - Optional. This string being printed once before the related posts list (only if there is 1 related post or more)
 $between - Optional. This string being printed between 2 entries in the related posts list.
 $after - Optional. This string being printed once after the related posts list (only if there is 1 related post or more)
 $emptylist - Optional. This string being printed if there are no related posts.
 $id - Optional. The post id number to which the related posts list are shown. Defaults to the current post or page.

Examples:

If you write <?php the_crossreferences() ?> you get an output such as (here without hyperlinks):

  • <ul><li>Post title 1</li><li>Post title 2</li><li>Post title 3</li></ul> (if there are 3 related posts)
  • Nothing (if there are no related posts)

If you write <?php the_crossreferences('See also:', '; ', '.') ?> you get an output such as:

  • See also: Post title 1; Post title 2; Post title 3. (if there are 3 related posts)
  • Nothing (if there are no related posts)

If you write <?php the_crossreferences('See also:', '; ', '.',0,'There are currently no related posts.') ?> you get an output such as:

  • See also: Post title 1; Post title 2; Post title 3. (if there are 3 related posts)
  • There are currently no related posts. (if there are no related posts)

If you write <?php the_crossreferences('<h2>Related posts</h2><ul><li>') ?> you get an output such as:

  • <h2>Related posts</h2><ul><li>Post title 1</li><li>Post title 2</li></ul> (if there are 2 related posts)
  • Nothing (if there are no related posts)

If you write <h2>Related posts</h2><?php the_crossreferences() ?> you get an output such as:

  • <h2>Related posts</h2><ul><li>Post title 1</li><li>Post title 2</li></ul> (if there are 2 related posts)
  • <h2>Related posts</h2> (if there are no related posts)

It is better to enclose the call to the_crossreferences() within a if function_exists() block, otherwise your template will raise an error if the plugin is inactive.

if (function_exists('the_crossreferences')) the_crossreferences();

Function `get_the_crossreferences`

Same as above, but you get a string instead of an output to screen:

$string = get_the_crossreferences($before,$between,$after,$id,$emptylist);

Template Funtion Filters

There are the following filters available for the functions the_crossreferences() and get_the_crossreferences():

`cref_order_by`

With this filter you can define the sort order of the related posts list. Examples:

Place this at the functions.php file of your template in order to sort the related posts from older to newer:

add_filter('cref_order_by','mytheme_order_by');
function mytheme_order_by() { return 'post_date'; }

Place this in order to sort the related posts by post title:

add_filter('cref_order_by','mytheme_order_by');
function mytheme_order_by() { return 'post_title'; }

Place this in order to sort the related posts by post title descending Z-A:

add_filter('cref_order_by','mytheme_order_by');
function mytheme_order_by() { return 'post_title DESC'; }

`cref_post_from`

With this filter you can define how the link to a related post is shown.

Parameters: $default, $post

  • $default - The default appearence (hyperlinked post title)
  • $post - Related post info. You can use this properties:

    $post->ID - The ID number
        $post->post_title - Post Title
        $post->post_excerpt - Post Excerpt
        $post->post_content - Post Content
        etc. (all fields from the table wp_posts)
    

Examples:

Place this at your template to get each related post as: <hyperlinked post title> (<author>, <date>)

add_filter('cref_post_from','mytheme_post_from',10,2);
function mytheme_post_from($default,$post) {
    $author = get_author_name($post->post_author);
    $date = mysql2date(get_option('date_format'),$post->post_date);
    return "$default ($author, $date)";
}

Place this to get the same as above but being the whole (not just the title) hyperlinked to the related post:

add_filter('cref_post_from','mytheme_post_from',10,2);
function mytheme_post_from($default,$post) {
    $url = get_permalink($post->ID);
    $title = $post->post_title;
    $author = get_author_name($post->post_author);
    $date = mysql2date(get_option('date_format'),$post->post_date);
    return '<a href="'.$url.'">'.$title.' ('.$author.', '.$date.')</a>';
}

`cref_before`

`cref_between`

`cref_after`

`cref_emptylist`

With this filters you can control the parameters of the template function (s. above).

Requires: 2.5 or higher
Compatible up to: 2.7.1
Last Updated: 2009-2-8
Downloads: 4,546

Ratings

4 stars
4 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1
100,1,1
100,1,1