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 the following. Set ‘taxcat’ to true to filter the related downloads by category. Or, set it to false to filter by tag.

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

However, the 2 examples 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,// true to filter by tag, false to filter by category
);
$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);

10 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

    • 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 the 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

  3. How to remove the product title ?
    show only featured image is showing.

    Ageng D Prastyawan

    December 8th, 2014 at 11:24 pm

    • I will add this feature to the next release. If you need an immediate solution, you can remove the product title with these 2 steps:

      1. Comment out line 77 in the file “widget-edd-related.php”. It looks like this:

      code snippet
      <p><?php echo strip_tags( the_title('','', false) ); ?></p>
      

      2. In the file “edd-related-downloads.php”, change line 184 from this:

      code snippet
      echo strip_tags( the_title('','', false) ); ?>
      

      to just this:

      code snippet
      ?>
      
      Isabel

      December 9th, 2014 at 11:30 am

      • Thank you :)

        Ageng D Prastyawan

        December 9th, 2014 at 8:38 pm

Questions and Comments are Welcome

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

Please wrap PHP code in bracket tags like this:

[php]
YOUR CODE HERE 
[/php]

and HTML/CSS code in bracket tags like this:

[html]
YOUR CODE HERE 
[/html]