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:

  1. top level page: list shouldn't display @ all.
  2. second level page: list should display child pages of current page.
  3. 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

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -