Post Index Helpers

説明

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

テンプレート タグ

The plugin provides thirteen template tags for use in your theme templates.

Functions

  • <?php function c2c_get_last_index( $wp_query = null ) ?>
    Gets the index number for the last post in the loop listing
  • <?php function c2c_get_post_by_index( $index, $wp_query = null ) ?>
    Get post based on specified index
  • <?php function c2c_get_posts_by_index( $indexes, $wp_query = null ) ?>
    Get posts based on specified array of indexes
  • <?php function c2c_get_the_index( $wp_query = null ) ?>
    Get the index for the current post
  • <?php function c2c_is_at_index( $index, $wp_query = null ) ?>
    Is the current index at the specified index?
  • <?php function c2c_is_even( $wp_query = null ) ?>
    Is the current post at an even position? (i.e. 0, 2, 4, …)
  • <?php function c2c_is_first( $wp_query = null ) ?>
    Is the current post the first listed post?
  • <?php function c2c_is_last( $wp_query = null ) ?>
    Is the current post the last listed post?
  • <?php function c2c_is_odd( $wp_query = null ) ?>
    Is the current post at an odd position? (i.e. 1, 3, 5, …)
  • <?php function c2c_is_index_within( $start_index, $end_index, $index = null, $wp_query = null ) ?>
    Is the current post (or one at the specified index) within the bounds of a specified range?
  • <?phh function c2c_is_post_in_loop( $post_id, $wp_query = null ) ?>
    Is the specified post within the current loop?
  • <?php function c2c_is_valid_index( $index, $wp_query = null ) ?>
    Is the specified index valid? Validity is defined as being within the range of indexes actively occupied by posts in the current loop listing.
  • <?php function c2c_the_index( $wp_query = null ) ?> or more safely <?php do_action( 'c2c_the_index', $wp_query ); ?>
    Echo the current post’s index

Arguments

  • $index
    Integer value representing an index.

  • $indexes
    Array of integer values representing indexes.

  • $wp_query
    (optional) A custom WP_Query object. If null or not defined, then the global wp_query object is used. (Specifying this is not typical.)

  • $start_index
    Integer value representing the index at the start of the range (value is inclusive)

  • $end_index
    Integer value representing the index at the end of the range (value is inclusive)

  • $post_id
    Integer value representing the ID of the post.

  • Only show thumbnail for the first listed post.

  • Add a class name that includes the post’s index number, i.e. post-index-0 indicates the first post

    <

    div class=”post post-index-“>

  • Supply a “stripe” class if the post is at an odd index.

    <

    div class=””>

インストール

  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

評価

このプラグインにはレビューがありません。

貢献者と開発者

Post Index Helpers はオープンソースソフトウェアです。以下の人々がこのプラグインに貢献しています。

貢献者

“Post Index Helpers” をあなたの言語に翻訳しましょう。

開発に興味がありますか ?

コードを閲覧するか、SVN リポジトリをチェックするか、開発ログRSS で購読してみてください。

変更履歴

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+

1.3 (2020-05-28)

  • Change: In c2c_the_index(), echo an empty string if index is invalid
  • Change: In c2c_get_the_index(), ensure object property exists before referencing it
  • Change: Use HTTPS for link to WP SVN repository in bin script for configuring unit tests
  • Change: Note compatibility through WP 5.4+
  • Change: Explicitly document optional arguments as such, per WP core documentation standards
  • Change: Update links to coffee2code.com to be HTTPS
  • Change: Unit tests: Add tests for c2c_the_index()

1.2.9 (2019-12-23)

  • Change: Note compatibility through WP 5.3+
  • Change: Update copyright date (2020)

Full changelog is available in CHANGELOG.md.