Support » Plugins » Hacks » custom image on different category posts on home page

  • Resolved eurynome9999


    On my home page using my index.php file I display a custom image & link on each post. I want to be able to display a different image for posts from a specific category using in_category. What I have returns the first image but not the second, the other posts display no image. Why is my “else” not working?

    <p><?php the_content('') ?></p>
    <div class="xReadMore">
    <?php  if (in_category( '327' )): ?>
    <a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_url'); ?>/images/readMore-VIDEO.png" alt="" /></a>
    <?php else : ?>
    <a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_url'); ?>/images/ readMoreContent.jpg " alt="" /></a>
    <?php endif; ?>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your posted code may now have been permanently damaged/corrupted by the forum’s parser.]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael


    Forum Moderator

    it would help to see your site to check the output of the code.


    might be caused by the space after / in here:
    ?>/images/ readMoreContent.jpg

    Looks right maybe try:

    <p><?php the_content('') ?></p>
    <div class="xReadMore">
    <?php  if (in_category( '327' )){ ?>
    <a>"><img src="<?php bloginfo('template_url'); ?>/images/readMore-VIDEO.png" alt="" /></a>
    <?php }else{ ?>
    <a>"><img src="<?php bloginfo('template_url'); ?>/images/ readMoreContent.jpg" alt="" /></a>
    <?php } ?>

    Thank you both alchymyth and tornontoast for your rapid responses. Tornontoast’s solution worked perfectly! Thanks again you guys are great!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom image on different category posts on home page’ is closed to new replies.