WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 down vote accepted

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

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
$pages = get_pages('child_of=681&depth=1');
$count = count($pages);
share|improve this answer
Please add an explanation to your answer: why could that solve the problem? – toscho 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 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.