Post Index Helpers

Description

This plugin provides thirteen handy template tags that relate to the index/position of a post within a loop’s listing of posts.

Some of the template tags provided by this plugin relate to the position of the current post within the current loop:

  • c2c_is_first()
  • c2c_is_last()
  • c2c_is_at_index()
  • c2c_is_even()
  • c2c_is_odd()
  • c2c_get_the_index()
  • c2c_is_index_within()
  • c2c_the_index()

Other functions help you get a post (or posts) at a given position in the current loop:

  • c2c_get_post_by_index()
  • c2c_get_posts_by_index()

While the remaining three functions relate to index information about the loop in general:

  • c2c_get_last_index()
  • c2c_is_post_in_loop()
  • c2c_is_valid_index()

Please see the Template Tags section (in some places found under the Other Notes section) for descriptions of all the functions and their arguments.

Note that index counting begins at 0, which means the first item has an index of 0. An index of -1 indicates no posts were found.

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

Developer Documentation

Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the numerous template tags provided by the plugin.

As an overview, these are the template tags provided the plugin:

  • c2c_get_last_index() : Gets the index number for the last post in the loop listing
  • c2c_get_post_by_index() : Get post based on specified index
  • c2c_get_posts_by_index() : Get posts based on specified array of indexes
  • c2c_get_the_index() : Get the index for the current post
  • c2c_is_at_index() : Is the current index at the specified index?
  • c2c_is_even() : Is the current post at an even position? (i.e. 0, 2, 4, …)
  • c2c_is_first() : Is the current post the first listed post?
  • c2c_is_last() : Is the current post the last listed post?
  • c2c_is_odd() : Is the current post at an odd position? (i.e. 1, 3, 5, …)
  • c2c_is_index_within() : Is the current post (or one at the specified index) within the bounds of a specified range?
  • c2c_is_post_in_loop() : Is the specified post within the current loop?
  • c2c_is_valid_index() : Is the specified index valid?
  • c2c_the_index() : Echo the current post’s index

Installation

  1. Install via the built-in WordPress plugin installer. Or download and unzip post-index-helpers.zip inside the plugins directory for your site (typically wp-content/plugins/)
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  3. Use one or more of the provided template tags in theme template file(s) as desired

Reviews

There are no reviews for this plugin.

Contributors & Developers

“Post Index Helpers” is open source software. The following people have contributed to this plugin.

Contributors

Translate “Post Index Helpers” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

1.4.2 (2021-10-02)

  • New: Add DEVELOPER-DOCS.md and move template tag documentation into it
  • Change: Note compatibility through WP 5.8+
  • Unit tests:
    • Change: Restructure unit test directories
      • Change: Move phpunit/ into tests/phpunit/
      • Change: Move phpunit/bin/ into tests/
    • Change: Remove ‘test-‘ prefix from unit test file
    • Change: In bootstrap, store path to plugin file constant
    • Change: In bootstrap, add backcompat for PHPUnit pre-v6.0

1.4.1 (2021-04-15)

  • Change: Note compatibility through WP 5.7+
  • Change: Update copyright date (2021)

1.4 (2020-08-25)

  • New: Support action invocation as alternative to calling c2c_the_index()
  • New: Add TODO.md for newly added potential TODO items
  • 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+

Full changelog is available in CHANGELOG.md.