wordpress - How to find out what level of hierarchy the current page is? -
on wordpress site, want display list of pages in current site section. needs different levels of pages depending on level in hierarchy current page resides.
for instance:
- top level page: list shouldn't display @ all.
- second level page: list should display child pages of current page.
- third level page: list should display sibling pages , child pages.
what simplist way find out level of heirarchy current page on?
the simplest way i've found is:
$level = count(get_post_ancestors( $post->id )) + 1;
this gives number indicating depth of current page. 1 top level, 2 second level, etc. can switch code based on number such:
switch($level) { case 1: // top level page code; break; case 2: // second level page code; break; case 3: // third level page code; break; // etc. }
Comments
Post a Comment