Forums

[resolved] Two if statements in a row? (5 posts)

  1. hilj
    Member
    Posted 4 years ago #

    This works like it should:

    <?php
    	if (is_category('18'))
    		{
    		include(TEMPLATEPATH . '/blog.php');
    		}
    	else { ?>
            ...rest of the page
    <?php }

    This doesn't:

    <?php
    	if (is_category('18'))
    		{
    		include(TEMPLATEPATH . '/blog.php');
    		}
            if (is_category('29'))
    		{
    		include(TEMPLATEPATH . '/pagelinks.php');
    		}
    	else { ?>
            ...rest of the page
    <?php }

    How should I ad the second if statement? This is just something really simple, I'm just learning php.

    I'm using WP as CMS, goal is to generate blog and links from their own pages.

    All help is very much appreciated!

  2. SimonJ
    Member
    Posted 4 years ago #

    Hello.

    <?php
    	if (is_category('18'))
    		{
    		include(TEMPLATEPATH . '/blog.php');
    		}
            elseif (is_category('29'))
    		{
    		include(TEMPLATEPATH . '/pagelinks.php');
    		}
    	else { ?>

    Note the "elseif" in your second condition...

    S.

  3. hilj
    Member
    Posted 4 years ago #

    Okay, i see. I assume same goes for third and more statements.

    Thank you for you super fast reply!

  4. SimonJ
    Member
    Posted 4 years ago #

    Yes, for any other condition following the first "if", you should use "elseif".

    S.

  5. ashgrove
    Member
    Posted 3 years ago #

    Is it possible to have multiple categories in one statement?

    Something like:

    <?php
    	if (is_category('18, 19, 20'))
    		{
    		include(TEMPLATEPATH . '/blog.php');
    		}
            elseif (is_category('27, 28, 29'))
    		{
    		include(TEMPLATEPATH . '/pagelinks.php');
    		}
    	else { ?>

    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic