• Resolved caddyx

    (@caddyx)


    I’m just a WordPress user, but am trying to may some tweaks to my pages. On my post pages (single.php) I would like to display an image in the post unless it is in a particular category. Just picking up tidbits here and there, this is what I tried:
    ————

    <?php
    $findme   = 'My Category';
    $pos = strpos($category->cat_name, $findme);
    
    if ($pos === false) {
        echo
    '<a href="https://www.test.com/"><img class="alignright right size-full wp-image-34" title="Test" src="https://www.test.com/test.gif" alt="Image Link" width="228" height="152" /></a>';
    }
    ?>

    ————-
    The result I am getting is that it displays the image no matter what the category or categories of the post. When I did “echo $pos”, it didn’t display anything.

    Any help would be greatly appreciated. Specific code would be wonderful! I don’t really know PHP and am just getting my feet wet.

    Thanks!

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

    (@vtxyzzy)

    See if this will do what you want:

    <?php
    $findme   = 'My Category';
    if (!in_category($findme)) {
        echo
    '<a href="https://www.test.com/"><img class="alignright right size-full wp-image-34" title="Test" src="https://www.test.com/test.gif" alt="Image Link" width="228" height="152" /></a>';
    }
    ?>
    Thread Starter caddyx

    (@caddyx)

    Yes! It works perfectly. Thank You, Thank You, Thank You.

    vtxyzzy

    (@vtxyzzy)

    You are welcome!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display an image on post page if NOT specific category’ is closed to new replies.