Loop Post Navigation Links

Loop Post Navigation Links

Wordpress plugin

Install on Wordpress

App Details

This plugin provides two template tags for use in single.php to create a post navigation loop, whereby previous to the first post is the last post, and after the last post is first post. Basically, when you’re on the last post and you click to go to the next post, the link takes you to the first post. Likewise, if you’re on the first post and click to go to the previous post, the link takes you to the last post.

The function c2c_next_or_loop_post_link() is identical to WordPress’s next_post_link() in every way except when called on the last post in the navigation sequence, in which case it links back to the first post in the navigation sequence.

The function c2c_previous_or_loop_post_link() is identical to WordPress’s previous_post_link() in every way except when called on the first post in the navigation sequence, in which case it links back to the last post in the navigation sequence.

Useful for providing a looping link of posts, such as for a portfolio, or to continually present pertinent posts for visitors to continue reading.

If you are interested in getting the post itself and not just a link to the post, you can use the c2c_get_next_or_loop_post() and c2c_get_previous_or_loop_post() functions. If you just want the URL to the post, you can use c2c_get_next_or_loop_post_url() and c2c_get_previous_or_loop_post_url().

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Template Tags

The plugin provides four template tags for use in your single-post theme templates.

Functions

  • function c2c_next_or_loop_post_link( $format='%link »', $link='%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
    Like WordPress’s next_post_link(), this function displays a link to the next chronological post (among all published posts, those in the same category, or those not in certain categories). Unlink next_post_link(), when on the last post in the sequence this function will link back to the first post in the sequence, creating a circular loop.

  • function c2c_get_next_or_loop_post_link( $format='%link »', $link='%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
    Like `c2c_next_or_loop_post_link(), but returns the value without echoing it.

  • function c2c_previous_or_loop_post_link( $format='« %link', $link='%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
    Like WordPress’s previous_post_link(), this function displays a link to the previous chronological post (among all published posts, those in the same category, or those not in certain categories). Unlink previous_post_link(), when on the first post in the sequence this function will link to the last post in the sequence, creating a circular loop.

  • function c2c_get_previous_or_loop_post_link( $format='« %link', $link='%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
    Like `c2c_get_previous_or_loop_post_link(), but returns the value without echoing it.

  • function c2c_get_next_or_loop_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
    Like WordPress’s get_adjacent_post() when used to find the next post, except when on the last post in the sequence this function will return the first post in the sequence, creating a circular loop.

  • function c2c_get_previous_or_loop_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
    Like WordPress’s get_adjacent_post() when used to find the previous post, except when on the first post in the sequence this function will return the last post in the sequence, creating a circular loop.

  • function c2c_get_next_or_loop_post_url( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
    Returns the URL for the next post or the post at the beginning of the series.

  • function c2c_get_previous_or_loop_post_url( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
    Returns the URL for the previous post or the post at the end of the series.

Arguments

  • $format
    (optional) A percent-substitution string indicating the format of the entire output string. Use %link to represent the next/previous post being linked, or %title to represent the title of the next/previous post.

  • $link
    (optional) A percent-substitution string indicating the format of the link itself that gets created for the next/previous post. Use %link to represent the next/previous post being linked, or %title to represent the title of the next/previous post.

  • $in_same_term
    (optional) A boolean value (either true or false) indicating if the next/previous post should be in the current post’s same taxonomy term.

  • $excluded_terms
    (optional) An array or comma-separated string of category or term IDs to which posts cannot belong.

  • $taxonomy
    (optional) Taxonomy, if $in_same_term is true. Default ‘category’.

Examples

<div class="loop-navigation"> <div class="alignleft"><?php c2c_previous_or_loop_post_link(); ?></div> <div class="alignright"><?php c2c_next_or_loop_post_link(); ?></div> </div><h3>Hooks</h3> 

The plugin is further customizable via eleven hooks. Typically, code making use of hooks should ideally be put into a mu-plugin, a site-specific plugin (which is beyond the scope of this readme to explain), or in theme template files. Many of these filters are likely only of interest to advanced users able to code.

c2c_previous_or_loop_post_link_output, c2c_next_or_loop_post_link_output (filters)

The ‘c2c_previous_or_loop_post_link_output’ and ‘c2c_next_or_loop_post_link_output’ filters allow you to customize the link markup generated for previous and next looping links, respectively.

Arguments:

  • $format (string): Link anchor format.
  • $link (string): Link permalink format.
  • $in_same_term (bool): Optional. Whether link should be in a same taxonomy term. Default is false.
  • $excluded_terms (array|string): Optional. Array or comma-separated list of excluded term IDs. Default is ”.
  • $previous (bool): Optional. Whether to display link to previous or next post. Default is true.
  • $taxonomy (string): Optional. Taxonomy, if $in_same_term is true. Default ‘category’.
  • $adjacent (string): Whether the post is previous or next.

Example:

 <?php // Prepend "Prev:" to previous link markup. function my_custom_previous_or_loop_link_output( $output, $format, $link, $post, $in_same_term, $excluded_terms, $taxonomy ) { return 'Prev: ' . $output; } add_filter( 'c2c_previous_or_loop_post_link_output', 'my_custom_previous_or_loop_link_output', 10, 4 ); ?> 

c2c_previous_or_loop_post_link_get, c2c_next_or_loop_post_link_get (filters)

The ‘c2c_previous_or_loop_post_link_get’ and ‘c2c_next_or_loop_post_link_get’ filters allow you to customize the link markups generated for previous and next looping links, respectively, but in the non-echoing functions.

Arguments:

  • $output (string): The adjacent post link.
  • $format (string): Link anchor format.
  • $link (string): Link permalink format.
  • $post (WP_Post): The adjacent post.
  • $in_same_term (bool): Optional. Whether link should be in a same taxonomy term. Default is false.
  • $excluded_terms (array|string): Optional. Array or comma-separated list of excluded term IDs. Default is ”.
  • $previous (bool): Optional. Whether to display link to previous or next post. Default is true.
  • $taxonomy (string): Optional. Taxonomy, if $in_same_term is true. Default ‘category’.
  • $adjacent (string): Whether the post is previous or next.

c2c_previous_or_loop_post_link, c2c_next_or_loop_post_link, c2c_get_previous_or_loop_post_link, c2c_get_next_or_loop_post_link, c2c_get_adjacent_or_loop_post, c2c_get_previous_or_loop_post, c2c_get_previous_or_loop_post (actions)

The ‘c2c_previous_or_loop_post_link’ and ‘c2c_next_or_loop_post_link’ actions allow you to use an alternative approach to safely invoke c2c_previous_or_loop_post_link() and c2c_next_or_loop_post_link(), respectively, in such a way that if the plugin were deactivated or deleted, then your calls to the functions won’t cause errors in your site. The ‘c2c_get_previous_or_loop_post_link’ and ‘c2c_get_next_or_loop_post_link’ filters do the same for the non-echoing c2c_previous_or_loop_post_link() and c2c_next_or_loop_post_link().

Arguments:

  • Same as for for c2c_previous_or_loop_post_link() and c2c_next_or_loop_post_link()

Example:

Instead of:

<?php c2c_previous_or_loop_post_link( '<span class="prev-or-loop-link">&laquo; %link</span>' ); ?> 

Do:

<?php do_action( 'c2c_previous_or_loop_post_link', '<span class="prev-or-loop-link">&laquo; %link</span>' ); ?> 

Pricing

Starting from $0 per month.

Check Out the Nudge Button Widget

By Common Ninja

Nudge ButtonTry For Free!

App Info

Rating

Reviewers

12 reviews

Tags

links
navigation
next
posts
previous

Developed By

Scott Reilly

Quick & Easy

Find the Best Wordpress plugins for you

Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!

Testimonial

Testimonial plugins for Wordpress

Contact Form

Contact Form plugins for Wordpress

Maps

Maps plugins for Wordpress

Translation

Translation plugins for Wordpress

Chat

Chat plugins for Wordpress

Slider

Slider plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Contact

Contact plugins for Wordpress

Galleries

Galleries plugins for Wordpress

SEO

SEO plugins for Wordpress

Forms

Forms plugins for Wordpress

Comments

Comments plugins for Wordpress

Backup

Backup plugins for Wordpress

Privacy

Privacy plugins for Wordpress

Optimize

Optimize plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Comments

Comments plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Video Player

Video Player plugins for Wordpress

popup

popup plugins for Wordpress

SiteMap

SiteMap plugins for Wordpress

Payment

Payment plugins for Wordpress

Coming Soon

Coming Soon plugins for Wordpress

Inventory

Inventory plugins for Wordpress

Testimonials

Testimonials plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Membership

Membership plugins for Wordpress

Forms

Forms plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Sliders

Sliders plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Security

Security plugins for Wordpress

Ads

Ads plugins for Wordpress

Music Player

Music Player plugins for Wordpress

Countdown

Countdown plugins for Wordpress

Email Marketing

Email Marketing plugins for Wordpress

Membership

Membership plugins for Wordpress

Ecommerce

Ecommerce plugins for Wordpress

Customer Support

Customer Support plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

More plugins

plugins You Might Like

Discover Apps By Platform

Discover the best apps for your website

WordPress
Wix
Shopify
Weebly
Webflow
Joomla
PrestaShop
Shift4Shop
WebsiteX5
MODX
Opencart
NopCommerce

Common Ninja Search Engine

The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!

Multiple platforms