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?


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

$count = 0;
$pages = get_pages('child_of=681&depth=1');
  foreach($pages as $page) {
  echo $count;

Reference: get_pages

| improve this answer | |
  • Thanks! It worked! I'd upvote but I don't have enough rep points yet. I'll get you back. – Dan Jul 22 '11 at 21:25
$pages = get_pages('child_of=681&depth=1');
$count = count($pages);
| improve this answer | |
  • 2
    Please add an explanation to your answer: why could that solve the problem? – fuxia Oct 11 '13 at 12:52
  • Agreed. While correct, this provides no instruction. Anyone can copy a codebit. – Eric Holmes Oct 11 '13 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.