• Noisie

    (@noisie)


    For a project I want a dynamic header image on most pages. To do this I wanted to solve it with a thumbnail on each page.php. The problem I have is that archive and single pages are causing bugs because it also loads extra post_thumbnails. The code I have atm is:

    <?php if (is_home()) { ?>
    <div id=”myCarousel” class=”carousel slide”>
    <!– Carousel items not relevant –>
    </div>
    <?php } elseif (is_archive()) { ?>
    <img src=”<?php bloginfo(‘template_directory’);?>/assets/img/archive-img.jpg” alt=”” />
    <?php } elseif (is_single()) { ?>
    <img src=”<?php bloginfo(‘template_directory’);?>/assets/img/single-img.jpg” alt=”” />
    <?php } elseif (has_post_thumbnail()) { ?>
    <?php the_post_thumbnail(‘header-thumbnail’); ?>
    <?php } else { ?>
    <img src=”<?php bloginfo(‘template_directory’);?>/assets/img/custom-img.jpg” alt=”” />
    <?php } ?>

    Strange thing is it works perfect at my archive pages (It loads the image I called but on single pages it still loads the single post thumbnail instead of the header thumbnail.

    I marked the header thumbnail with: the_post_thumbnail(‘header-thumbnail’) and single post thumbnail with the_post_thumbnail(‘single-thumbnail’) with the correct markup in my functions.php.

    Anyone got a clue what I am doing wrong? I know the php can be shorter but its just a project to test what is possible so I can optimize it later on.

  • The topic ‘Bug with post_thumbnail’ is closed to new replies.