Simply Related Posts, a WordPress Widget Plugin to relate Posts by taxonomy the easy way

I know, there are a lot of widgets out there, to print related posts, but none of them I tested really suited my needs. First of all I think  a widget shouldn’t have a whole bunch of global settings, rather no global settings at all, I mean, it’s just a widget. But, even if I don’t like a huge settings page, just to run a little widget, there has to be some flexibility to let me adjust every widget-instance to my needs.

The Simply Related Posts Widget

In the case of related posts I couldn’t find a widget that really did what I wanted so I build my own. There are no global settings, but every widget instance has four options:

  1. The title of the widget (default: Related Posts). It is similar to all other widget titles and gets printed before the widget-content.
  2. The taxonomy by which terms the posts are related (default: Tags). A post is related to another post, as soon it they share one or more terms of a taxonomy. This can be the standard taxonomies Tags and Categories, or Custom taxonomies. Here youchoose which taxonomy is the relating one.
  3. How many related posts to show (default 5). Quite simple, put the maximal number of related posts you want to be visible here.
  4. Terms to exclude (default: none). Sometimes there are terms in a taxonomy, which are related to almost every post. The tag wordpress in my blog is such an example. If you have such tags you should exclude them, because they relate basically all posts, which would make the widget quite uselessscreenshot-1

Installing

  1. Download the plugin from the directory: Simply Related Posts
  2. Unpack and upload the simply-related-posts folder to the /wp-content/plugins/directory
  3. Activate the plugin through the ‘Plugins’ menu in WordPress
  4. Go to the ‘Apearance/Widgets’ area, add the ‘Simply Related Posts’ widget to a widget area.
  5. Make your settings

Feedback

Of course I want your feedback: Bugs or feature requests are welcome in the comments of this post or via twitter and I appreciate every review.

For now the code is available via svn from the plugin directory:
http://plugins.svn.wordpress.org/simply-related-posts/

Now, there is even a github repository:
http://github.com/danielauener/wp-simply-related-posts

Tagged with:

14 thoughts on “Simply Related Posts, a WordPress Widget Plugin to relate Posts by taxonomy the easy way

  1. Hi,

    many thanks for this simple and pure widget.
    could you post the code which we can use to visualize the related posts under a post itselfe, e.g. in the single.php?

    Krgds
    Stefan

    1. Hi Stefan,

      you could define a new widget area in your single.php template. There is an excellent article on automattic.com. Here is how you do it in short:

      1. Register a widget area in your functions.php

          function yourtheme_widgets_init() {
              register_sidebar( array(
                  'name' => __( 'Single Post Widgets'),
                  'id' => 'widgets-single',
                  'description' => __( 'Widgets added here will be displayed on single posts.' ),
              ) );
          }
          add_action( 'widgets_init', 'yourtheme_widgets_init' );
      

      2. Add the Simply Related Posts widget to the new area which should be popping up on the widgets page in your admin interface.

      3. Load the widget area in your single.php file

      <ul id="sidebar">
          <?php if ( !dynamic_sidebar() ) : ?>
              <li><?php _e('No Widgets added.'); ?></li>
          <?php endif; ?>
      </ul>
      

      4. If you like the plugin, I would be happy to get a review on wordpress.org 😉

    1. Hi, are there other widgets showing up in the sidebar? Try to add an simple text-widget and check if it appears in the sidebar, so we know that the sidebar itself works.
      Then you have to check if it is a single template you try to include the widget on, otherwise it wouldn’t show up.
      You can test to disable all other plugins as well to see if one of them is causing the problem and of corse there have to be some related posts and relations to show.
      If all that doesn’t work I need more information about your setup, are there custom post types, taxonomies or other functionality?

  2. Hi!

    Thanks for building a great and simple plugin 🙂

    I added a fix to support custom types, just by taking the post_type from the $instance and using it in the query.

    I thought it might help others and it won’t hurt to add it to the codebase.

    Cheers!

        $post_type = $instance['post_type'];
        
        $related_posts = get_posts( array(
            'tax_query' => array( array(
                'taxonomy' => $taxonomy,
                'field' => 'id',
                'terms' => $terms,
                'operator' => 'IN'
            ) ),
           'post_type' => $post_type,
           'posts_per_page' =&gt; $instance['related_count'],
           'exclude' =&gt; get_the_ID()
        ) );
    
  3. This is an interesting post. Though I did not understood much of it because I am a designer and as far as coding is concerned, I am only familiar with little bit of JavaScript coding. I have installed wordpress websites and also plugins but never dared to create a plugin myself for the obvious reasons.

  4. Hi, Daniel,

    Just a quick question for some clarification:

    I’d like to have a WooCommerce product display posts that are related by tags, but also on a single post page, display WC products that are related by tag.

    Is it possible to accomplish this with Simply Related Posts?

  5. Hi,

    I really like the keep it simple approach!

    The only problem that this plugin is not respecting the multilingual post/page titles. Instead simply cut the language tags, and merge all the multi language titles to one string.

    Not sure if its a bug or a missing feature 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *