Posted By

cyberhobo on 08/17/09


Tagged

pages wordpress root wordpress-template page-hierarchy root-page


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

tobiasmay
umang_nine
gerrit
maxvee8
lawlesscreation


WordPress: Get the root page ID


 / Published in: PHP
 

URL: http://codex.wordpress.org/Template_Tags/wp_list_pages#List_subpages_even_if_on_a_subpage

Get the ID of the root (oldest ancestor, parent without parents) page relative to the current page in a WordPress page template.

Can be helpful for use with wp_list_pages() to create navigation markup.

  1. <?php $root_page_id = ( empty( $post->ancestors ) ) ? $post->ID : end( $post->ancestors ); ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ttr738 on May 21, 2010

cheers! very helpful and completely missed it in the codex!

You need to login to post a comment.