In the event Google brings more visitors here, I am doing the exact same thing as spiralstarez only the purpose is to prevent XSS injection into the URL of wordpress pages. So I need to know what I think my permalink should be before I call get_header();. :-(
This handy gem will get you for pages what get_category_parents() does for posts. I guess I should have called it get_page_parents()... :)
function page_ancestory( $id=0, $separator="/" ){
$itisme=get_post($id);
$lineage=$itisme->post_name;
$parentID=$itisme->post_parent;
while( $parentID != 0 ){
$parent=get_post($parentID);
$lineage=$parent->post_name.$separator.$lineage;
$parentID=$parent->post_parent;
}
return $lineage;
}
echo page_ancestory($post->ID);
In spiralstarez's case, the output would be:
about/1/1.1/1.2/1.2.1/1.2.2
Assuming that the above "words" are page "slugs".
OH! I forgot to mention that $post works anywhere on a "page" template for me, so doesn't need to be in the loop.
Reference: codex for get_post()
Also, be aware that $post->post_content IS the whole page (or post) itself, so this child of the object can be bigger than you might think ... and spools out ALL of that html and if you're not paying attention, you think something broke, when it actually didn't.
To see what's going on with an array or object, I will do this:
<pre><?
print_r($post);
?></pre>
But in our case, this makes the "page" twice as long and the only hint is the preformatting of the "post_content". To make things better, if I am working outside the loop, I will often do this:
<pre><?
unset($post->post_content);
print_r($post);
?></pre>
Which will make the output more friendly:
[ID] => 146
[post_author] => 1
[post_date] => 2007-12-12 12:53:28
[post_date_gmt] => 2007-12-12 20:53:28
[post_content] =>
[post_title] => Terms & Conditions
[post_category] => 0
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => terms-conditions
[to_ping] =>
[pinged] =>
[post_modified] => 2007-12-14 14:47:54
[post_modified_gmt] => 2007-12-14 22:47:54
[post_content_filtered] =>
[post_parent] => 6
[guid] => http://qa.mydomain.com/wordpress/policies/terms-conditions
[menu_order] => 0
[post_type] => page
[post_mime_type] =>
[comment_count] => 0
And from seeing this, you can see that this post's parent is policies (from the guid) and policies's ID is 6.
:) Chris