• This is my code

    <?php
     if (in_category(array(33,34,35,38,39,40))
     && is_user_logged_in()){ ?>
    <a href="https://url" rel="nofollow">CLICK HERE </a>
    <?php  }  ?>
    
    <?php
     if (in_category(array(32,53,54,55))
    && is_user_logged_in()){ ?>
    <a href="https://url" rel="nofollow">CLICK HERE </a>
    <?php } ?>

    I am calling it with include TEMPLATE .
    In some single post both links show up, how do I fix this. How do I end the first if statement or is there a better way to write this.
    any help is welcome. Thank you in advance.

Viewing 1 replies (of 1 total)
  • In some single post both links show up

    probably because the post has categories from both arrays.

    if you want the first if to have ‘first pick’ you could try to work with if/elseif:

    <?php
     if (in_category(array(33,34,35,38,39,40))
     && is_user_logged_in()){ ?>
    <a href="https://url" rel="nofollow">CLICK HERE </a>
    <?php  }  ?>
    
    <?php
     elseif (in_category(array(32,53,54,55))
    && is_user_logged_in()){ ?>
    <a href="https://url" rel="nofollow">CLICK HERE </a>
    <?php } ?>

    https://www.w3schools.com/php/php_if_else.asp

Viewing 1 replies (of 1 total)
  • The topic ‘How to end if statement. I tried everything I’ve read so far.’ is closed to new replies.