views:

82

answers:

2

Basically I am trying to show something like "Viewing PageNumber of TotalNumberOfPages" in each subpage for a specific parent page. So i am trying to figure out how to count the number of sub-pages/child pages that exist and display them on a subpage?

+1  A: 

You can use count(get_pages('child_of' => page_id)) to get the number of sub-pages. But in order to display that it's for example page 2/5 you have to define somewhere which sub-page is which number. I'd suggest you do that in a custom field. Just put 1, 2, 3, 4, 5, respectively in a custom field in each page that you call number or something.

Calle
A: 

To build on Calle's answer.

//get the sub pages for the parent page
    $subPages = get_pages('child_of'=>parent_page_id);
    //$i will equal the page number
    $i=1;
    foreach($subPages as $subs){
        //not sure what the exact array key for page_id will be. use var_dump($subPages)to find out
        //make the array key the page id for use later (as current_page_id)
        $pageNumber[$subs->page_id] = $i;
    }
    $numberPages = count($pageNumbers);

Then show the page count and number pages for the page you are on.

echo 'vewing page '.$pageNumber[current_page_id].' of '.$numberPages;
kevtrout