Plugin Directory

Yet Another Related Posts Plugin

Display a list of related entries on your site and feeds based on a unique algorithm. Now with thumbnail support built-in!

Developing with YARPP

Custom post types

To make YARPP support your custom post type, the attribute yarpp_support must be set to true on the custom post type when it is registered. It will then be available on options on the YARPP settings page.

If you would like to programmatically control which post types are considered in an automatically-displayed related posts display, use the yarpp_map_post_types filter.

Custom displays

Developers can call YARPP's powerful relatedness algorithm from anywhere in their own code. Some examples and more details are in my slides from my WordCamp Birmingham talk.

yarpp_related(array(
    // Pool options: these determine the "pool" of entities which are considered
    'post_type' => array('post', 'page', ...),
    'show_pass_post' => false, // show password-protected posts
    'past_only' => false, // show only posts which were published before the reference post
    'exclude' => array(), // a list of term_taxonomy_ids. entities with any of these terms will be excluded from consideration.
    'recent' => false, // to limit to entries published recently, set to something like '15 day', '20 week', or '12 month'.

    // Relatedness options: these determine how "relatedness" is computed
    // Weights are used to construct the "match score" between candidates and the reference post
    'weight' => array(
        'body' => 1,
        'title' => 2, // larger weights mean this criteria will be weighted more heavily
        'tax' => array(
            'post_tag' => 1,
            ... // put any taxonomies you want to consider here with their weights
        )
    ),
    // Specify taxonomies and a number here to require that a certain number be shared:
    'require_tax' => array(
        'post_tag' => 1 // for example, this requires all results to have at least one 'post_tag' in common.
    ),
    // The threshold which must be met by the "match score"
    'threshold' => 5,

    // Display options:
    'template' => , // either the name of a file in your active theme or the boolean false to use the builtin template
    'limit' => 5, // maximum number of results
    'order' => 'score DESC'
),
$reference_ID, // second argument: (optional) the post ID. If not included, it will use the current post.
true); // third argument: (optional) true to echo the HTML block; false to return it

Options which are not specified will default to those specified in the YARPP settings page. Additionally, if you are using the builtin template rather than specifying a custom template file in template, the following arguments can be used to override the various parts of the builtin template: before_title, after_title, before_post, after_post, before_related, after_related, no_results, excerpt_length.

If you need to use related entries programmatically or to know whether they exist, you can use the functions yarpp_get_related($args, $reference_ID) and yarpp_related_exist($args, $reference_ID). yarpp_get_related returns an array of post objects, just like the WordPress function get_posts. yarpp_related_exist returns a boolean for whether any such related entries exist. For each function, $args takes the same arguments as those shown for yarpp_related above, except for the various display and template options.

Note that custom YARPP queries using the functions mentioned here are not cached in the built-in YARPP caching system. Thus, if you notice any performance hits, you may need to write your own code to cache the results.

Custom taxonomy support

Any taxonomy, including custom taxonomies, may be specified in the weight or require_tax arguments in a custom display as above. term_taxonomy_ids specified in the exclude argument may be of any taxonomy.

If you would like to choose custom taxonomies to choose in the YARPP settings UI, either to exclude certain terms or to consider them in the relatedness formula via the UI, the taxonomy must (a) have either the show_ui or yarpp_support attribute set to true and (b) must apply to either the post types post or page or both.

Localizations

YARPP is currently localized in the following languages:

Requires: 3.3 or higher
Compatible up to: 3.6
Last Updated: 2013-4-15
Downloads: 2,381,384


Support

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

Got something to say? Need help?

Compatibility

+
=
Works!

11 people say it works.
4 people say it's broken.

100,1,1 50,4,2 100,3,3 100,1,1
50,2,1 86,14,12 100,3,3 100,1,1 100,1,1 100,1,1
88,16,14 100,1,1 100,1,1 100,1,1 100,1,1 100,1,1 100,2,2
100,2,2 100,1,1 33,3,1 92,12,11 100,1,1 100,5,5 100,1,1 100,1,1 100,1,1 100,1,1 100,1,1
70,23,16 100,1,1 100,1,1
100,3,3 100,4,4 100,8,8 70,10,7 90,21,19 67,6,4
67,3,2 53,19,10 52,21,11 100,1,1
80,45,36 100,1,1 0,1,0 50,2,1 0,1,0
100,1,1
83,6,5
86,7,6 100,1,1 0,1,0
100,1,1 67,3,2 0,1,0
80,5,4 73,11,8 70,10,7 60,10,6 100,1,1 100,1,1 100,2,2
100,12,12 100,1,1
78,9,7 100,1,1 100,1,1
100,6,6 100,1,1 70,10,7
67,3,2
86,14,12 50,2,1 100,1,1
86,7,6 42,24,10 68,22,15 25,4,1 33,3,1 100,5,5 0,1,0
100,2,2 25,8,2 22,9,2 100,10,10 71,14,10
86,22,19 50,4,2 68,25,17 100,1,1
70,20,14 100,1,1 0,1,0
100,6,6 100,1,1
81,21,17 100,10,10 100,2,2 100,1,1
100,4,4 89,9,8 100,1,1 93,14,13 100,4,4 78,9,7 100,3,3 100,2,2 80,5,4 67,3,2 100,3,3 100,1,1 100,1,1
100,7,7 77,13,10 100,1,1
89,9,8 80,10,8 91,11,10 73,15,11