Created
June 22, 2011 06:01
-
-
Save hameedullah/1039575 to your computer and use it in GitHub Desktop.
Get Page Depth - Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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