• This may be easey but I’ve been looking and can not figure it out.
    I got the below from the codex…

    <?php if (is_category('Category A')) { ?>
    <p>This is the text to describe category A</p>
    <?php } elseif (is_category('Category B')) { ?>
    <p>This is the text to describe category B</p>
    <?php } else { ?>
    <p>This is some generic text to describe all other category pages,
    I could be left blank</p>
    <?php } ?>

    Basically I want to continue to add to that but if I were to add..

    <?php if (is_category('Category A')) { ?>
    <p>This is the text to describe category A</p>
    <?php } elseif (is_category('Category B')) { ?>
    <p>This is the text to describe category B</p>
    <em><?php } elseif (is_category('Category C')) { ?>
    <p>This is the text to describe category C</p></em>
    <?php } else { ?>
    <p>This is some generic text to describe all other category pages,
    I could be left blank</p>
    <?php } ?>

    it breaks it.

    I want to use the above but need to add about 6 more categories.
    How can I ad more statements to that code so I don’t get errors?

    Any help would be appreciated.

    Jon

Viewing 4 replies - 1 through 4 (of 4 total)
  • modesignz

    (@modesignz)

    instead of opening the <?php and closing ?> and then opening another one and closing for each line, why not have one <?php for all the code:

    <?php
    	if (is_category('Category A'))
    	{
    
    		<p>This is the text to describe category A</p>
    
    	}
    	elseif (is_category('Category B'))
    	{
    		<p>This is the text to describe category B</p>
    		<?php
    	}
    	else
    	{
    		<p>This is some generic text to describe all other category pages,
    		I could be left blank</p>
    
    	}
    
    ?>

    Hope this helped ??

    t31os

    (@t31os)

    Nope sorry that’s incorrect and will not function…

    With PHP you will need to echo out the HTML content…
    It would be like this without opening and closing PHP…

    <?php
    	if (is_category('Category A'))
    	{
    		echo 'This is the text to describe category A
    ';
    	}
    	elseif (is_category('Category B'))
    	{
    		echo 'This is the text to describe category B
    ';
    	}
    	else
    	{
    		echo 'This is some generic text to describe all other category pages,
    		I could be left blank
    ';
    
    	}
    
    ?>

    modesignz

    (@modesignz)

    oh yh sorry…i didn’t see that one…thanx ??

    Im using the folowing script in my Sidebar to show specific menu depending on the categories :

    <?php
    if (is_category(‘recipe’)){ include (TEMPLATEPATH . ‘/sidebar-recipe.php’); }
    else { include (TEMPLATEPATH . ‘/sidebar-main.php’); }
    ?>

    It works great. My only problem is that I would like to include all the sub-categories of the categories “recipe”, so that everything under it (child) will have the same sidebar. Something like : if (is_category_and_child …

    Otherwise if I cant do that, I would like to be able to include more than one categories in the tag, but I cant find the right syntax. Something like : if (is_category(‘recipe’, ‘deserts’, ‘soup’, ‘lamb’, ‘etc…’ ))

    Thanks a lot.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘php if is_category question’ is closed to new replies.