WordPress.org

Ready to get started?Download WordPress

Forums

How to recursively apply a "Featured image" to sub pages? (4 posts)

  1. robotor
    Member
    Posted 2 years ago #

    Hello, just as the subject states, I am looking for a way to recursively apply a featured image downward to any sub pages, while allowing for a sub page featured image (if set) to override a parent's featured image. Is this possible?

    thanks :)

  2. ujgreg
    Member
    Posted 2 years ago #

    I am hunting down an answer for this as well, robotor. Did you find anything since you posted?

  3. ujgreg
    Member
    Posted 2 years ago #

    I'm getting close, mashing up code like a Primanti Brothers sandwich from various readings, codex etc.

    I need this to do "if is parent, display current featured. Else display 1st level featured image." The code below only displays the parent page of the child pages so when in 3rd level it displays the 2nd level apparently. Not sure about overriding but it's a step closer than where I was.

    <div id="featured">
     <?php if (has_post_thumbnail( $post->post_parent ) ): ?>
     <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->post_parent ), 'single-post-thumbnail' ); ?>
     <div id="featured-bg">
     <img src="<?php echo $image[0]; ?>" alt="Title here" />
     <div id="featured-caption"><?php echo the_post_thumbnail_caption(); ?></div>
     </div>
     <?php endif; ?>
  4. ujgreg
    Member
    Posted 2 years ago #

    I have a solution here with the option to override the parent page's featured image with a featured image added to a child page.

    Let me know if you have any trouble with it or feedback/improvements. I'll likely re-use this for a ton of projects and improve it as needed.

Topic Closed

This topic has been closed to new replies.

About this Topic