Title: php if is_category question
Last modified: August 19, 2016

---

# php if is_category question

 *  [jonj](https://wordpress.org/support/users/jonj/)
 * (@jonj)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/php-if-is_category-question/)
 * 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](https://wordpress.org/support/users/modesignz/)
 * (@modesignz)
 * [17 years, 3 months ago](https://wordpress.org/support/topic/php-if-is_category-question/#post-839259)
 * 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](https://wordpress.org/support/users/t31os/)
 * (@t31os)
 * [17 years, 3 months ago](https://wordpress.org/support/topic/php-if-is_category-question/#post-839260)
 * 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](https://wordpress.org/support/users/modesignz/)
 * (@modesignz)
 * [17 years, 3 months ago](https://wordpress.org/support/topic/php-if-is_category-question/#post-839261)
 * oh yh sorry…i didn’t see that one…thanx 🙂
 *  [minougris](https://wordpress.org/support/users/minougris/)
 * (@minougris)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/php-if-is_category-question/#post-839269)
 * 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.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 4 participants
 * Last reply from: [minougris](https://wordpress.org/support/users/minougris/)
 * Last activity: [17 years, 1 month ago](https://wordpress.org/support/topic/php-if-is_category-question/#post-839269)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
