1

Need help from a developer. I'm using an if else statement in my wordpress theme to render two different kinds of single post templates. Now I have to add another template. The present code is:

$post = $wp_query->post;
    if ( in_category('1204') ) {
        include(TEMPLATEPATH . '/1204-article.php');
        }

    else {
        include(TEMPLATEPATH . '/regular-article.php');
        }

I want to include/append an additional statement that if in_category('345') then include 345-article.php else include regular-article.php

Thanks.

1 Answer 1

2

Just add another else if, i.e.:

$post = $wp_query->post;
if ( in_category('1204') ) 
{
    include(TEMPLATEPATH . '/1204-article.php');
}
else if ( in_category('345') ) 
{
      include (TEMPLATEPATH . '/345-article.php');
}
else 
{
    include(TEMPLATEPATH . '/regular-article.php');
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks ryan.. what if I have to include two category id's? I tried putting in else if (in_category('345', '15') but it doesn't seem to work. Should I create another else if statement for category 15?
You could do that, but if the two categories lead to the same include, you could combine them with else if (in_category('345') || in_category('15')). The || operator means OR.
Please mark the question as answered if this solved your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.