• Great plugin, thanks Scott.
    I have very little php knowledge, so it took a while for me to figure out how to implement this properly, but I figured it out (finally) and am posting this for anyone that comes after. My goal was to install it and use it for cycling through posts– one instance for all posts in the same category, some in all categories. Here’s how I went about it after installing this plugin:

    1) I installed the INCLUDE ME plugin first. This isn’t necessary if you plan on placing the Looped Nav items into the single.php template, but I was inserting into a Divi text module, and this plugin allows for the retrieval of PHP and other files into page content via shortcode.

    2) Set up the code for the version which cycles through the same category and placed it into a file called infinite-postnav-same-cat.php. Here it is:

    <div class="loop-navigation same-category">
        <div class="alignleft">
          <?php c2c_previous_or_loop_post_link( $format='&laquo; %link', $link='%title', $in_same_term = true, $excluded_terms = '', $taxonomy = 'category' ); ?>
      </div>
        <div class="alignright">
          <?php c2c_next_or_loop_post_link( $format='%link &raquo;', $link='%title', $in_same_term = true, $excluded_terms = '', $taxonomy = 'category' ); ?>
      </div>
    </div>

    The part that makes it cycle through the same category is changing $in_same_term to “True” in both cases. Other attributes can be changed as needed.

    4) Then I linked to that php file through a shortcode from the Include Me plugin:
    [includeme file=”wp-content/themes/MyChildTheme/added-functions/infinite-postnav-samecategory.php”]

    5) And lastly, placed that shortcode into a text module in a Divi post.

    After that, I repeated the process for the version that loops through all categories: Created a php file, named it appropriately, added the code into it, created the shortcode, and then applied the shortcode where I needed it in Divi. The only difference in the version that cycles through all the posts, is that the $in_same_term attribute was changed back to “false”. To make this EXTRA easy, here is that version:

    <div class="loop-navigation same-category">
        <div class="alignleft">
          <?php c2c_previous_or_loop_post_link( $format='&laquo; %link', $link='%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ); ?>
      </div>
        <div class="alignright">
          <?php c2c_next_or_loop_post_link( $format='%link &raquo;', $link='%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ); ?>
      </div>
    </div>

    ===
    Like I mentioned at the start, if you don’t need to insert the nav links anywhere with shortcodes, then you would skip the part about the Include Me plugin, and the individual php files, and instead take the code I placed in either of the php documents, and paste it into your child theme’s single.php file where appropriate. Keep in mind though, that with this method, I believe you can only use one of the options (instead of one that works exclusively with categories, and one without).

  • The topic ‘Implementation Tips’ is closed to new replies.