WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Inheriting Page Parents Thumbnail (7 posts)

  1. Rellston
    Member
    Posted 2 years ago #

    Hi guys,

    i just wanted to know, if there's an easy way to let Child-Pages inherit their parent pages thumbnail?

  2. Digital Raindrops
    Member
    Posted 2 years ago #

    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

  3. Rellston
    Member
    Posted 2 years ago #

    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.

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    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');
    }
  5. Rellston
    Member
    Posted 2 years ago #

    Wow thanks alot guys!

  6. Digital Raindrops
    Member
    Posted 2 years ago #

    @alchymyth,
    I was very close for untested code!

    @Rellston
    Could you mark this topic as resolved please!

    David :)

  7. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    @David

    no doubt about that ;-)

    and the core idea about getting the right page ID for the thumbnail is perfect.

Topic Closed

This topic has been closed to new replies.

About this Topic