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
3.0.2 (2020-08-26)
Highlights:
This minor update has some minor tweaks that should go unnoticed, restructures unit test file structure, adds a
TODO.md file, and notes compatibility through WP 5.5+.
Details:
- Change: Unset loop flag in class just after it's used to ensure it gets reset
- Change: Escape URL for post before being output in link (hardening)
- Change: Restructure unit test file structure
- New: Create new subdirectory
phpunit/
to house all files related to unit testing
- Change: Move
bin/
to phpunit/bin/
- Change: Move
tests/bootstrap.php
to phpunit/
- Change: Move
tests/
to phpunit/tests/
- Change: Rename
phpunit.xml
to phpunit.xml.dist
per best practices
- Change: Note compatibility through WP 5.5+
- Unit tests:
- New: Add test for hook registrations
- New: Add tests for
modify_nextprevious_post_where()
3.0.1 (2020-05-10)
- Change: Use HTTPS for link to WP SVN repository in bin script for configuring unit tests
- Change: Note compatibility through WP 5.4+
- Change: Update links to coffee2code.com to be HTTPS
3.0 (2020-01-28)
Highlights:
- Significant update after a long hiatus! Adds functions for getting the URL of the previous/next post, modernizes unit tests, adds CHANGELOG.md, adds plugin to GitHub, changes plugin initialization, updates compatibility to be for WP 4.9-5.3+, and many other documentation and behind-the-scenes changes.
- Note that there is an incompatible fix for missing and incorrect arguments for the
c2c_{$adjacent}_or_loop_post_link_output
filter. This change won't affect you unless you have custom code making use of the filter, which is unlikely for almost all users.
Details:
- New: Add
c2c_get_next_or_loop_post_url()
and c2c_get_previous_or_loop_post_url()
to get URL of adjacent/looped post
- New: Add CHANGELOG.md file and move all but most recent changelog entries into it
- New: Add README.md file
- New: Add TODO.md and move existing TODO list from top of main plugin file into it (and add more items to the list)
- New: Add inline documentation for hooks
- New: Add GitHub link to readme.txt
- Fix: Add missing argument
$previous
and remove argument $post
from c2c_{$adjacent}_or_loop_post_link_output
hook invocation
- Change: Add
$adjacent
argument to a number of filters, to sync with WP core
- Adds to
{$adjacent}_post_link
, {$adjacent}_or_loop_post_link
, c2c_{$adjacent}_or_loop_post_link_get
, and c2c_{$adjacent}_or_loop_post_link_output
- Change: Use
c2c_get_adjacent_or_loop_post()
to obtain post, rather than duplicating its functionality in c2c_get_adjacent_or_loop_post_link()
- Change: Remove unnecessary (and incorrect) determination of adjacent post in
c2c_adjacent_or_loop_post_link()
- Change: Use a different variable name to avoid changing variable sent as function argument and later passed as argument to filter
- Change: Initialize plugin on 'plugins_loaded' action instead of on load
- Change: Use
apply_filters_deprecated()
to formally deprecate the {$adjacent}_or_loop_post_link
filter
- Change: Update code formatting to match modern WordPress standards
- Change: Remove
load_textdomain()
and just load the textdomain within init()
- Unit tests:
- Change: Change
expected()
to optionally not include arrow quotes
- Change: Update unit test install script and bootstrap to use latest WP unit test repo
- Change: Enable more error output for unit tests
- Change: Comment out unit tests that weren't actually testing anything
- Fix: Don't declare
$posts
as being static since it's never referenced as if it was
- New: Add tests for hooks
- Change: Note compatibility through WP 5.3+
- Change: Drop compatibility with versions of WP older than 4.9
- Change: Include documentation on filter arguments
- Change: Tweak formatting for installation instructions
- Change: Remove documentation for non-existent parameters of
modify_nextprevious_post_where()
- Change: Remove unnecessary
echo
in code example
- Change: Modify formatting of hook name in readme to prevent being uppercased when shown in the Plugin Directory
- Change: Rename readme.txt section from 'Filters' to 'Hooks' and provide a better section intro
- Change: Update License URI to be HTTPS
- Change: Update copyright date (2020)
- Change: Update installation instruction to prefer built-in installer over .zip file
Full changelog is available in CHANGELOG.md.