• tomleads

    (@tomleads)


    Hi.

    Getting a bit mixed up with my conditional statements.

    I need to change the body class if it is a category/archive page. but if the category is Reviews or Opinions, it needs to be a slightly different class.

    <?php
    if (is_home()) {
    echo '<body class="page-home">';
    } elseif (is_search()) {
    echo '<body class="page-search">';
    } elseif (is_category('Reviews')) {
    echo '<body class="page-reviews">';
    } elseif (is_category('Opinion')) {
    echo '<body class="page-opinion">';
    } elseif (is_category()) {
    echo '<body class="page-archive">';
    } elseif (is_single()) {
            if (in_category('Reviews')) {
    			echo '<body class="page-reviews">';
            } elseif (in_category('Opinion')) {
    			echo '<body class="page-opinion">';
            } else {
    			echo '<body class="page-site">';
            }
    } else {
    echo '<body class="page-site">';
    }
    ?>

    must be getting something mixed up there. Help please! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • MichaelH

    (@michaelh)

    The first bunch looks okay…but this block makes no sense

    } elseif (is_single()) {
            if (in_category('Reviews')) {
    			echo '<body class="page-reviews">';
            } elseif (in_category('Opinion')) {
    			echo '<body class="page-opinion">';
            } else {
    			echo '<body class="page-site">';
            }

    If you are in a single post template you would need to put the in_category in your loop.

    Related:
    Conditional Tags
    in_category
    Category Templates
    Template Hierarchy

    Thread Starter tomleads

    (@tomleads)

    Hi.

    That section actually works ok.

    I need to check the archive/category page template.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is not in category’ is closed to new replies.