Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer

up vote 1 down vote accepted

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

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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