wordpress get_parent function
I was looking for a way to get the parent ID of the current subpage recently and could not find an available function on the codex pages. I needed this function in order to create a navigation that is always based on the current page. The site I was working on has no more than 3 levels of navigation, so I needed a way for the deepest sub-pages to generate the same side navigation as the 2nd level pages. I wrote this short simple function.
Hopefully someone may find it usefull.
//Gets the parent ID of a post or page
function get_parent($parent) {
global $wp_query;
$return = $wp_query->post->post_parent;
return $return;
}
Recently

November 30th, 2008 at 12:16 pm
Quite useful, I might say.
Thanks
March 18th, 2009 at 6:27 pm
Hi Sir,
I was thinking of using your code as breadcrumbs for my pages.
but since im a Newbie wordpress coder here. Im pretty unsure on how do i implement this? do i just place your code in the functions.php?
how do i call it from the theme?
July 22nd, 2009 at 1:15 pm
Thanks a lot, very useful to me.
July 29th, 2009 at 11:24 am
Thank you so much for this simple function. Works like a charm
@Noel yes, drop this in your functions.php file. Then call it.
Cris
August 16th, 2009 at 11:33 am
Where i have to insert this code ? (In wich file)
Thanks
January 8th, 2010 at 6:19 am
Nice Code. Helped me quite a bit. thanks