Page 1 of 1

Count parent/child pages

Posted: Fri Aug 27, 2021 11:23 pm
by ctuxboy
Hello,

What is the best way show total number of:
- childpages
- parent pages

This code shows the total number of ALL published pages:

Code: Select all

<?php echo count($pages->getList(1, -1, true)); ?>

Re: Count parent/child pages

Posted: Sun Aug 29, 2021 9:05 pm
by ctuxboy
Found a solution counting the children-pages...

Code: Select all

<?php 
    // Count ALL dogzones
    // Page number of the paginator, the first page is 1
    $pageNumber = 1;

    // The value -1 tell to Bludit to returns all the pages on the system
    $numberOfItems = -1;

    // Only get the pages with the satus published
    $onlyPublished = true;

    // Get the list of keys of pages
    $items = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);

    $count = 0;

    foreach ($items as $key) {
      // buildPage function returns a Page-Object
      $page = buildPage($key);
      $children = $page->children();

      // Each child is a Page-Object
      foreach ($children as $child) {
        $count++;
      }
    }
   // print the result
   echo '<p>' . $count . '</p>';
?>