Forums

How to end if statement. I tried everything I've read so far. (2 posts)

  1. Geofeedz
    Member
    Posted 2 years ago #

    This is my code

    <?php
     if (in_category(array(33,34,35,38,39,40))
     && is_user_logged_in()){ ?>
    <a href="http://url" rel="nofollow">CLICK HERE </a>
    <?php  }  ?>
    
    <?php
     if (in_category(array(32,53,54,55))
    && is_user_logged_in()){ ?>
    <a href="http://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.

  2. alchymyth
    The Sweeper
    Posted 2 years ago #

    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="http://url" rel="nofollow">CLICK HERE </a>
    <?php  }  ?>
    
    <?php
     elseif (in_category(array(32,53,54,55))
    && is_user_logged_in()){ ?>
    <a href="http://url" rel="nofollow">CLICK HERE </a>
    <?php } ?>

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

Topic Closed

This topic has been closed to new replies.

About this Topic