WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP Call Parent Thumbnail (2 posts)

  1. JonWicks25
    Member
    Posted 1 year ago #

    I'm currently working on my own theme, I only have it locally sadly.

    Basically in the header I have a the navigation and then the featured image of the page, then a second navigation menu

    ---------- Nav --------
    ----- Feature Image -----
    -------- 2nd Nav --------

    I want only the parent pages to have featured images, and so the on a child page the feature image should be the same as it's parent,

    this is my code

    <?php
       if ( is_page('home')) {
         echo '<div style="float: left;">';
         echo riva_slider_pro( 1 );
         echo '</div>';
    } else if (is_page('our-clients' || 'our-services' || 'about' || 'our-team' || 'our-sectors' || 'information' || 'partners' || 'contact-us')) {
         echo '<div style="height: 170px;">';
         echo get_the_post_thumbnail($page->ID, 'full');
         echo '</div>';
    } else  {
         echo '<div style="height: 170px;">';
         echo get_the_post_thumbnail($post->post_parent, 'full');
         echo '</div>';
     }
    ?>

    Individually each piece works fine, but all together I can't get the child pages to pull the same featured image as the parent. Am I missing something simple?

    Thanks

  2. JonWicks25
    Member
    Posted 12 months ago #

    Never mind got it sorted. If anyone else is having similar problems this is the correct code I used

    <?php
    if ( is_page('home')) {
       echo '<div style="float: left;">';
       echo riva_slider_pro( 1 );
       echo '</div>';
    } else if (is_page('our-clients') || is_page('our-services') || is_page('our-team') || is_page('our-sectors') ||  is_page('information') || is_page('partners') || is_page('contact-us') || is_page('about')) {
       echo '<div style="height: 170px;">';
       echo get_the_post_thumbnail($page->ID, 'full');
       echo '</div>';
    } else  {
       echo '<div style="height: 170px;">';
       echo get_the_post_thumbnail($post->post_parent, 'full');
       echo '</div>';
    }
    ?>

    I had the coding for else if (is_page('page') || wrong

Topic Closed

This topic has been closed to new replies.

About this Topic