WordPress.org

Plugin Directory

Related

A simple 'related posts' plugin that lets you select related posts manually.

Option 1 - Automatic install

Use the plugin installer built into WordPress to search for the plugin. WordPress will then download and install it for you.

Option 2 - Manual install

  1. Make sure the files are within a folder.
  2. Copy the whole folder inside the wp-content/plugins/ folder.
  3. In the backend, activate the plugin. You can now select related posts when you create or edit blog posts, pages etc.

How to display the related posts on your website

The related posts are displayed by adding

<?php global $related; echo $related->show( $post_id ); ?>

to your template. Replace $post_id with a post ID. If you call it within the WordPress loop, you can use

<?php global $related; echo $related->show( get_the_ID() ); ?>

You have the option of either outputting a pre-formatted list or returning a PHP array of related posts to customise the markup yourself.

Examples

Example 1: Using the default output

<?php global $related; echo $related->show( get_the_ID() ); ?>

This can be called within the WordPress loop. It will output a <ul> list with links.

Example 2: Returning an array

<?php
    global $related;
    $rel = $related->show( get_the_ID(), true );
?>

With the second argument set to true, it will return an array of post objects. Use it to generate your own custom markup. Here is an example:

<?php
    global $related;
    $rel = $related->show( get_the_ID(), true );

    // Display the title of each related post
    if( is_array( $rel ) && count( $rel ) > 0 ) {
        foreach ( $rel as $r ) {
            if ( is_object( $r ) ) {
                if ($r->post_status != 'trash') {
                    echo get_the_title( $r->ID ) . '<br />';
                }
            }
        }
    }
?>

If you want to run it with a real WordPress loop, then use it as follows. You can then use functions like the_content or the_excerpt. But make sure you don't use the content filter for related posts, because you might get an endless stream of related posts that are related to each other :).

<?php
    global $related;
    $rel = $related->show( get_the_ID(), true );

    // Display the title and excerpt of each related post
    if( is_array( $rel ) && count( $rel ) > 0 ) {
        foreach ( $rel as $r ) {
            if ( is_object( $r ) ) {
                if ($r->post_status != 'trash') {
                    setup_postdata( $r );
                    echo get_the_title( $r->ID ) . '<br />';
                    the_excerpt();
                }
            }
        }
        wp_reset_postdata();
    }
?>

Using the default output from the Related (Doubled Up) plugin:

<?php global $related_du; echo $related_du->show( get_the_ID() ); ?>

This can be called within the WordPress loop. It will output a <ul> list with links.

Requires: 3.3 or higher
Compatible up to: 4.2
Last Updated: 2015-4-25
Active Installs: 1,000+

Ratings

5 out of 5 stars

Support

2 of 2 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

1 person says it works.
0 people say it's broken.

100,1,1
100,1,1
0,1,0
100,1,1
100,1,1
100,1,1
0,1,0
100,1,1
100,1,1
100,1,1
100,1,1 100,1,1 100,1,1 100,1,1 100,1,1 100,1,1
100,1,1 100,1,1
100,1,1 100,1,1
100,1,1 100,1,1
100,1,1 100,1,1
100,1,1 100,1,1
100,1,1
100,1,1 100,1,1 100,1,1
100,1,1 100,1,1 100,2,2 100,1,1 100,1,1 100,1,1 100,2,2 100,1,1 100,1,1
100,1,1