Easiest way to show total number of subpages

I am making a portfolio site where each portfolio entry is a subpage of “Work”. In my template, I am trying to say something like: worked on 15 projects and counting, where 15 is the total number of subpages.

Whats the easiest way to do this?

2 Answers
2

Use the following code, replacing the number after “child_of=” to the id of the parent page.

<?php
$count = 0;
$pages = get_pages('child_of=681&depth=1');
  foreach($pages as $page) {
    $count++;
  }
  echo $count;
?>

Reference: get_pages

Leave a Comment