You can test on $post->post_parent
, which will hold the ID of the parent Page (if there is one). More on retrieving the parent here:
http://wordpress.org/support/topic/38264#post-216237
Thread Starter
hathor
(@hathor)
Thanks for the advice! Unfortunately I get an error:
Fatal error: Unsupported operand types in /homepages/1/d21520737/htdocs/wordpress/wp-includes/template-functions-post.php on line 74
Line 74 is:
$content = $pages[$page-1];
It displays the id and name of the parent page correctly, but then I get the error and of course the rest is missing.
It placed your code it the page template:
<?php
$page = $wp_query->post;
$parent_name = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE ID = '$page->post_parent;'");
$parent_post = $post->post_parent;
?>
<?php echo $parent_name . "" . $parent_post; ?>
Is there a mistake?
Oh, I’m using WP 1.5.1.3.
The code you have works fine for me.
Don’t know why you’re receiving that error. It relates to the get_the_content() function, has nothing to do with Page parents and the like, and the $page variable above should not be conflicting with it. Nonetheless, try this mod:
<?php
$thispage = $wp_query->post;
$parent_name = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE ID = '$thispage->post_parent;'");
$parent_post = $post->post_parent;
?>
Thread Starter
hathor
(@hathor)
Hmm, may be the error occurs because of a plugin that I’m using?
Anyway, it works now with the code above. 🙂
Thank you very much for taking the time! 🙂