$page->index() method

Return the index/position of this page relative to siblings.

If given a hidden or unpublished page, that page would not usually be part of the group of siblings. As a result, such pages will return what the value would be if they were visible (as of 3.0.121). This may overlap with the index of other pages, since indexes are relative to visible pages, unless you specify an include mode (see next paragraph).

If you want this method to include hidden/unpublished pages as part of the index numbers, then specify boolean true for the $selector argument (which implies "include=all") OR specify a selector of "include=hidden", "include=unpublished" or "include=all".

Available since version 3.0.24.

Example

$i = $page->index();
$n = $page->parent->numChildren();
echo "This page is $i out of $n total pages";

Usage

// basic usage
$int = $page->index();

// usage with all arguments
$int = $page->index($selector = '');

Arguments

NameType(s)Description
selector (optional)

Return value

int

Returns index number (zero-based)


$page methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #532
    In the 532nd issue of ProcessWire Weekly we'll cover the latest core updates, check out a couple of brand-new third party modules, and more. Read on!
    Weekly.pw / 20 July 2024
  • Page List Custom Children module
    This simple module gives you the ability to customize the parent/child relationship as it appears in the admin page list, enabling child pages to appear under more than one parent.
    Blog / 28 June 2024
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH