Count parent/child pages

Post Reply
ctuxboy
Ssr. Bludit
Posts: 25
Joined: Sat Dec 15, 2018 11:37 pm
Has thanked: 4 times
Been thanked: 2 times

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)); ?>
ctuxboy
Ssr. Bludit
Posts: 25
Joined: Sat Dec 15, 2018 11:37 pm
Has thanked: 4 times
Been thanked: 2 times

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>';
?>
Post Reply