Not sure where you are using this but try:
UNTESTED:
<?php
global $post;
$parents = get_post_ancestors( $post->ID );
/* Get the ID of the 'top most' Page if not return current page ID */
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
if(has_post_thumbnail( $id )) {
the_post_thumbnail( $id, 'thumbnail');
}
?>
HTH
David
Thanks for the quick answer!
It’s not working tho 😉
Subpages shall have the same pic/thumbnail in the sidebar as the parent pages.
Our customer seems to be too laizy, to give the subpages the same thumbnail and i was looking for an automatic way to inherit the parent pages thumbnail for sites wich will be created after our work.
it is always the little things that make problems:
the_post_thumbnail() does not take the post ID as parameter;
get_the_post_thumbnail() does.
http://codex.wordpress.org/Function_Reference/the_post_thumbnail
http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
i.e. change the last few lines to:
if(has_post_thumbnail( $id )) {
echo get_the_post_thumbnail( $id, 'thumbnail');
}
@alchymyth,
I was very close for untested code!
@rellston
Could you mark this topic as resolved please!
David 🙂
@david
no doubt about that 😉
and the core idea about getting the right page ID for the thumbnail is perfect.