Support » Fixing WordPress » "If Category Then" on Single Post Page

  • Resolved atom8bit

    (@atom8bit)


    I’d like the following code to execute on the single.php page:

    <div>
    <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>
    <?php the_post_thumbnail('full') ?>
    <?php endif ?>
    </div>

    But only if in category 6. I’ve tried the following but get PHP errors:

    <?php
    if(is_category('6')){
    echo '<div>';
    if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) :
    the_post_thumbnail('full')
    endif
    }
    echo '</div>';
    } ?>

    Any insight is appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Something like this, using has_category should work:

    if ( has_post_thumbnail() && has_category( 6, $post ) {
    	printf( '<div>%s</div>', get_the_post_thumbnail( $post->ID, 'full' ) );
    }

    Well, that sort of worked… (isn’t that C syntax you’re using?)
    I actually did this and it ended up working, so either way your suggestion did help:

    <div>
    <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) && has_category( 6, $post )) : ?>
    <?php the_post_thumbnail('full') ?>
    <?php endif ?>
    </div>

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘"If Category Then" on Single Post Page’ is closed to new replies.