Anyone know how to count the number of child pages under a parent?

Discussion in 'WordPress' started by InfantryVet, May 7, 2011.

  1. #1
    Hey DP,

    I'm working on a site using WordPress that uses a lot of parent/child relationships.

    I've searched Google for some guidance (and even resorted to Bing), but I'm not having any luck.

    Imagine I'm setting up a site on recipes. Here would be my parent/child relationship:

    Italian Food (parent) => Lasagna (child)

    Now, the Italian Food parent will have quite a few child pages. For instance, Spaghetti, Chicken Tetrazzini, etc... You get the idea.

    In this example, I would like to display the number of child pages under the Italian Food parent.

    Something like this...

    Italian Food - 10 Recipes (each recipe is a child page of the Italian Food parent)
    Chinese Food - 5 Recipes (each recipe is a child page of the Chinese food parent)

    I'm not having any trouble returning each child page in a loop with the page title and custom field data, but I just can't figure out how to display the number of child pages under a parent.

    Any guidance would be greatly appreciated. You don't have to go all out and provide the exact code for me (although, I'd appreciate that even more), but any kind of advice on how to approach this problem will make my evening!

    Thanks in advance to anyone who tries to help me.

    -Jason
     
    InfantryVet, May 7, 2011 IP
  2. mccomf

    mccomf Active Member

    Messages:
    517
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Are they pages or categories? Wordpress has the option to display the posts count in categories.
     
    mccomf, May 8, 2011 IP