WP: Get Parent Subpage Count


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. //get the sub pages for the parent page
  3. $subPages = get_pages('child_of=parent_page_id');
  4. //$i will equal the page number
  5. $i=1;
  6. foreach($subPages as $subs){
  7. //not sure what the exact array key for page_id will be. use var_dump($subPages)to find out
  8. //make the array key the page id for use later (as current_page_id)
  9. $pageNumber[$subs->page_id] = $i;
  10. }
  11. $numberPages = count($pageNumbers);
  12.  
  13. // Then show the page count and number pages for the page you are on.
  14.  
  15. echo 'vewing page '.$pageNumber[current_page_id].' of '.$numberPages;
  16.  
  17. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.