WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] custom image on different category posts on home page (4 posts)

  1. eurynome9999
    Member
    Posted 1 year ago #

    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>
    <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; ?>
    </div>

    `
    [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.]

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

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

    link?

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

  3. tomontoast
    Member
    Posted 1 year ago #

    Looks right maybe try:

    <p><?php the_content('') ?></p>
                </div>
    <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 } ?>
    </div>
  4. eurynome9999
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic