• Resolved frusi

    (@frusi)


    Hey guys,

    I am using the following code for the single post:

    <?php
      $post = $wp_query->post;
      if (in_category('portfolio')) {
          include(TEMPLATEPATH.'/single_portfolio.php');
      } elseif (in_category('news')) {
          include(TEMPLATEPATH.'/single_news.php');
      } elseif(has_tag('review') && in_category('news')){
          include(TEMPLATEPATH.'/single_review.php');
      }
      else{
          include(TEMPLATEPATH.'/single_default.php');
      }
    ?>

    However, for the single_review I am checking if it’s inside category news and has tag “review”, but it’s not working. Any suggestions? Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • what is ‘not working’?

    from the sequence of your conditional statements, anything in the category ‘news’ will get the template ‘/single_news.php’ –

    rewrite the code, going from the specific to the general ….

    Thread Starter frusi

    (@frusi)

    @micheal thank you so much. You were right, it was enough to swap the order of the condition, I guess my brain was frying. For anyone else who might need this. Here s the working code.

    <?php
    $post = $wp_query->post;
    if (in_category(‘portfolio’)) {
    include(TEMPLATEPATH.’/single_portfolio.php’);
    } elseif(has_tag(‘review’) && in_category(‘news’)){
    include(TEMPLATEPATH.’/single_review.php’);
    } elseif (in_category(‘news’)) {
    include(TEMPLATEPATH.’/single_news.php’);
    }
    else{
    include(TEMPLATEPATH.’/single_default.php’);
    }
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Wp queries for single.php template’ is closed to new replies.