• How would I go about displaying certain additional featured images on certain pages? I am trying to target the post_id but it’s not working as I hoped. Thanks in advance for any direction. (I am using Multiple Featured Images plugin as a starting point.)

    functions.php:

    if( class_exists( 'kdMultipleFeaturedImages' ) ) {
    
            $args = array(
                    'id' => 'featured-image-2',
                    'post_type' => 'page',      // Set this to post or page
                    'labels' => array(
                        'name'      => 'Featured image 2',
                        'set'       => 'Set featured image 2',
                        'remove'    => 'Remove featured image 2',
                        'use'       => 'Use as featured image 2',
                    )
            );
    
            new kdMultipleFeaturedImages( $args );
    }

    page-template.php (where ” ’36’ ” references the post_id of the page I’m trying to display this featured image on):

    <div class="img-wrap">
    	<?php if( class_exists( 'kdMultipleFeaturedImages' ) ) {
    		kd_mfi_get_featured_image( 'featured-image-2', 'page', 'full', '36' );
    	} ?>
    </div>

    https://www.ads-software.com/plugins/multiple-featured-images/

Viewing 4 replies - 1 through 4 (of 4 total)
  • You are best to use an if statement. Try to avoid hard coding ids etc but this should solve your issue.

    page-template.php

    <?php if(get_the_ID() == 36 && class_exists( 'kdMultipleFeaturedImages' )):?>
    <div class="img-wrap">
    	 kd_mfi_the_featured_image( 'featured-image-2', 'post', 'full' );
    </div>
    <?php endif;?>

    Thread Starter emilyflannery

    (@emilyflannery)

    Thank you for your response. If statements to not seem to work. I’ve tried them in a variety of ways, both in functions.php and in the page template files. I was hoping to be able to pass an argument in the functions.php file when defining the featured image, but that doesn’t seem to work either.

    Are you trying to only show the option to add/remove a featured image or just only display the featured image on that particular ID?

    Thread Starter emilyflannery

    (@emilyflannery)

    I am trying to show the option in the Admin to give the client the ability to update if they need to. Creating additional post types seems unnecessary and will be confusing for them, and I also don’t want to give them the option to upload 4 different featured images on pages where only 1 should be uploaded, if that makes sense. That’s the reasoning for trying to distinguish between which pages display which featured images.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display featured images only on certain pages’ is closed to new replies.