Take the 2-minute tour ×
WordPress Development Stack Exchange 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

2 Answers 2

up vote 2 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
$pages = get_pages('child_of=681&depth=1');
$count = count($pages);
share|improve this answer
2  
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

 
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.