Skip to content

Instantly share code, notes, and snippets.

@hameedullah
Created June 22, 2011 06:01
Show Gist options
  • Save hameedullah/1039575 to your computer and use it in GitHub Desktop.
Save hameedullah/1039575 to your computer and use it in GitHub Desktop.
Get Page Depth - Wordpress
/*
Plugin Name: get_page_depth
Author: Hameedullah Khan
Aurhor URI: http://hameedullah.com
*/
/*
* get_page_depth
* Gets the page depth, calls get_post on every iteration
*/
function get_page_depth( $id=0, $depth=0 ) {
global $post;
if ( $id == 0 )
$id = $post->ID;
$page = get_post( $id );
if ( !$page->post_parent ) {
// this page does not have any parent
return $depth;
}
return get_page_depth( $page->post_parent, $depth+1 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment