Title: How to display outside loop on single.php?
Last modified: April 11, 2025

---

# How to display outside loop on single.php?

 *  Resolved [bcw00](https://wordpress.org/support/users/bcwint00/)
 * (@bcwint00)
 * [1 year ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/)
 * Hello. This is my code. I inserted it outside the loop on single.php and uploaded
   my custom file yarpp-template-bottom.php into my active theme.
 *     ```wp-block-code
       <?phpif (function_exists('yarpp_related')) {    yarpp_related(array(        'template' => get_stylesheet_directory() . '/yarpp-template-bottom.php', 'limit' => 4     ));}?>
       ```
   
 * However it outputs a basic ordered list of 4 related entries and is not using
   the custom theme YARPP file I uploaded. Any help?
    -  This topic was modified 1 year ago by [bcw00](https://wordpress.org/support/users/bcwint00/).

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Thread Starter [bcw00](https://wordpress.org/support/users/bcwint00/)
 * (@bcwint00)
 * [1 year ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18412787)
 * Found an easier solution with the shortcodes.
 *  [Saleswonder Support Team](https://wordpress.org/support/users/subscribetech/)
 * (@subscribetech)
 * [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18425360)
 * [@bcwint00](https://wordpress.org/support/users/bcwint00/) I am interested how
   you did it with the shortcode.
   Please share shortcode. thx Tobias
 *  Thread Starter [bcw00](https://wordpress.org/support/users/bcwint00/)
 * (@bcwint00)
 * [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18426010)
 * [@subscribetech](https://wordpress.org/support/users/subscribetech/) 
   It’s just
   basically the shortcode in a php wrapper. Here is an example. It’s saying to 
   use the yarpp-template-photoblog (you can change that to your own template) and
   limited to 3 posts. In the HTML itself, it has its own wrap, so you might have
   to add some additional styling if you’re mixing it in with something else. [https://wordpress.org/plugins/yet-another-related-posts-plugin/#installation](https://wordpress.org/plugins/yet-another-related-posts-plugin/#installation)
 *     ```wp-block-code
       <?php echo do_shortcode('[yarpp template="yarpp-template-photoblog" limit=3]'); ?>
       ```
   
 *  Plugin Author [meattle](https://wordpress.org/support/users/meattle/)
 * (@meattle)
 * [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18426140)
 * If you’re running outside the loop, we encourage setting `reference_id`
 *     ```wp-block-code
       <?php echo do_shortcode('[yarpp reference_id=123]'); ?>
       ```
   
 * …to show content related to post 123
 *  Plugin Author [meattle](https://wordpress.org/support/users/meattle/)
 * (@meattle)
 * [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18426147)
 * [@bcwint00](https://wordpress.org/support/users/bcwint00/)
 * Usage of `template`in your `yarpp_related` function example was incorrect. No
   need to specify the path. For example:
 *     ```wp-block-code
       <?php if (function_exists('yarpp_related')) {   yarpp_related(array(     'template' => 'yarpp-template-photoblog', 'limit' => 4   )); }?>
       ```
   
 * Your YARPP Custom Template file must be in the _active theme’s main directory_
   in order to be recognized by YARPP. The path is hardcoded for security.
 * `'template' => 'thumbnails', // which theme/custom template to use. Built-in 
   ones include "list" and "thumbnails", or the name of a YARPP template file in
   your active theme folder starting with "yarpp-template-". Example: yarpp-template-
   videos or yarpp-template-videos.php`
 *  Thread Starter [bcw00](https://wordpress.org/support/users/bcwint00/)
 * (@bcwint00)
 * [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18426149)
 * [@meattle](https://wordpress.org/support/users/meattle/) Not sure what you are
   referring to about the path. I mentioned they can use the name of the template(
   assuming they have one in their custom theme folder).
 *  Plugin Author [meattle](https://wordpress.org/support/users/meattle/)
 * (@meattle)
 * [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18426151)
 * [@bcwint00](https://wordpress.org/support/users/bcwint00/) in your original example(
   first post of the thread), you’re including the path by using “get_stylesheet_directory().
   This was not needed.
   Your example (incorrect):
 *     ```wp-block-code
       <?php  if (function_exists('yarpp_related')) {   yarpp_related(array(    'template' => get_stylesheet_directory() . '/yarpp-template-bottom.php', 'limit' => 4  )); }?>
       ```
   
 * The YARPP shortcode wraps the `yarpp_related` function.
 * Correct:
 *     ```wp-block-code
       <?php if (function_exists('yarpp_related')) {   yarpp_related(array(     'template' => 'yarpp-template-bottom', 'limit' => 4   )); }?>
       ```
   
 *  Thread Starter [bcw00](https://wordpress.org/support/users/bcwint00/)
 * (@bcwint00)
 * [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18426153)
 * [@meattle](https://wordpress.org/support/users/meattle/) Ohhh yea. I see what
   you mean, but I had figured that part before haha. That’s why I marked it solved
   so I wouldn’t waste your time.
 *  Plugin Author [meattle](https://wordpress.org/support/users/meattle/)
 * (@meattle)
 * [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18426154)
 * [@bcwint00](https://wordpress.org/support/users/bcwint00/) Yeah, got you 🙂 Just
   wanted to leave the correction for others who stumble upon this post.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘How to display outside loop on single.php?’ is closed to new replies.

 * ![](https://ps.w.org/yet-another-related-posts-plugin/assets/icon-256x256.png?
   rev=2549977)
 * [YARPP - Yet Another Related Posts Plugin](https://wordpress.org/plugins/yet-another-related-posts-plugin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yet-another-related-posts-plugin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/)
 * [Active Topics](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yet-another-related-posts-plugin/reviews/)

 * 10 replies
 * 3 participants
 * Last reply from: [meattle](https://wordpress.org/support/users/meattle/)
 * Last activity: [12 months ago](https://wordpress.org/support/topic/how-to-display-outside-loop-on-single-php/#post-18426154)
 * Status: resolved