Isabel Castillo

Web & Software Developer • I ♥ PHP

Easy Digital Downloads - Related Downloads - WordPress Plugin

Print

Position Related Downloads Using a Template Tag

Some of you don’t want the related downloads below the content, and the widget also fails to do what you want. So, you want a template tag that will let you position the related downloads anywhere on your single-download.php template.

You can accomplish this using WordPress’s function, the_widget. If you want the default output, use:

code snippet
the_widget('edd_related_downloads_widget');

If you want to specify parameters for this instance, use:

code snippet
$inst = array( 
        'title' => 'You May Also Like',
        'number' => 3,
        'taxcat' => false,
    );
the_widget('edd_related_downloads_widget', $inst, $args);

However, the 2 above will style it just like the sidebar widget, which is list-style. List-style means that the items are listed, one under each other. If you want this to appear grid-style (side-by-side), like the default related downloads that get added below the content, you have to add the $args parameter, like so (you can change the $inst, but not the $args if you want grid-style):

code snippet
$inst = array( 
    'title' => 'You May Also Like',
    'number' => 3,
    'taxcat' => false,
);
$args = array(
    'before_widget' => '<div id="isa-related-downloads" class="widget">',// make it grid-style
    'after_widget' => '</div>',
);
the_widget('edd_related_downloads_widget', $inst, $args);

7 Responses

  1. Hi Isabel
    I installed this wonderful plugin, I want to use related downloads in certain place of my single downloads page. so I put below line in my single-dolwnload.php:

    the_widget(‘edd_related_downloads_widget’);

    but it does not show any thing. by the way I do not know any php.

    Asi

    September 22nd, 2013 at 2:05 pm

    • Sorry for the delay. I just retested, and this works. Did you give a “tag” to your downloads? If there are no other downloads that share that download’s tag, then no related downloads will show up. Hope this helps.

      Isabel

      September 24th, 2013 at 4:59 pm

      • I test it, now works. but there is a little bug:

        when I put the code in the theme and tick the “Check this to filter by category. By default, downloads are related by tag” then it not works.

        Asi

        September 24th, 2013 at 5:44 pm

        • The “Related Downloads Settings” at “Downloads –> Settings –> Misc Tab” will only apply to the default related downloads which are added below the content. If you check the box to “Disable Related Downloads Added To Content“, then those settings will not work.

          So, if you are using the plugin by adding your line of code inside single-download.php, and you want you have to change the settings to filter by category, use this code instead of your 1 line:

          code snippet
          $inst = array(
                  'title' => 'You May Also Like',
                  'number' => 3,
                  'taxcat' => true, // Setting this to 'true' will filter by category. Setting it to 'false' will filter by tag.
              );
          the_widget('edd_related_downloads_widget', $inst);
          

          I will edit the second example on this page to make that more clear.

          Isabel

          September 24th, 2013 at 10:33 pm

          • thank you, works perfectly ;)

            Asi

            September 25th, 2013 at 3:55 am

  2. Thanks for this, it works great.

    Any idea how I can add it to regular posts as well?

    I tried to add it to single.php but I guess it’s not detecting the tag, as “single post” tags are different than “downloads” tags.

    Tony

    March 3rd, 2014 at 4:58 pm

    • Thank you. Yes, regular post “tags” are different from “download tags”. For regular posts, there are many plugins available. I haven’t tried them, but I would recommend these 2 (because they more popular ones are known to slow sites down):

      1. Related Posts by Taxonomy
      2. Efficient Related Posts

      I hope this helps.

      Isabel

      March 4th, 2014 at 9:46 am

Questions and Comments are Welcome

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>