Title: Conditional Tag Problems
Last modified: August 19, 2016

---

# Conditional Tag Problems

 *  Resolved [paul-davis](https://wordpress.org/support/users/paul-davis/)
 * (@paul-davis)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/conditional-tag-problems-1/)
 * Hello everyone.
      I’m building a quite complex site at the moment, and I’m having
   2 problems with the conditional tags. I know how to use them, and have used them
   successfully in past designs. Here’s my problems:   **1**, The current site I’m
   developing calls for a div to be loaded but only for it’s corresponding category.
   It works fine on the main parent category, but I also want it to show on each
   sub-category under the main one too. So I want it shown in _site.com/category/
   services_ and _site.com/category/services/more_. In-fact every sub-category under
   the main one.   Here’s the code I have now which is in the archive.php file: 
 *     ```
       <?php if (is_category('services')) { ?>
       	<div id="services_panel">
       		<!-- Image is loaded from CSS -->
       		<p><?php echo category_description(get_category_by_slug('services')->term_id); ?></p>
       	</div>
       <?php } ?>
       ```
   
 *  
        **2**, The conditional statement which works in the loop just before the
   posts will not work outside the loop. I want to load a sidebar that corresponds
   to the category the page is displaying.
 * Here’s that code too, also in the archive.php file.
 *     ```
       <?php else : ?>
       		<h2>Not Found</h2>
       	<?php endif; ?>
   
       	<div class="grid_4">
       		<?php if(is_category('services')) { ?>
       			<?php get_sidebar('services'); ?>
       		<?php } else { ?>
       			<p>if/else didnt work. =[</p>
       		<?php } ?>
       	</div>	
   
       <?php get_footer(); ?>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/conditional-tag-problems-1/#post-1116698)
 * Q1: Will this help?
    [http://codex.wordpress.org/Template_Tags/in_category#Testing_if_a_post_is_in_a_descendant_category](http://codex.wordpress.org/Template_Tags/in_category#Testing_if_a_post_is_in_a_descendant_category)
 * Q2: What about using in_category() – which will work outside the Loop in 2.7.1
   or above?
    [http://codex.wordpress.org/Template_Tags/in_category](http://codex.wordpress.org/Template_Tags/in_category)
 *  Thread Starter [paul-davis](https://wordpress.org/support/users/paul-davis/)
 * (@paul-davis)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/conditional-tag-problems-1/#post-1116817)
 * Hello esmi. Thanks for the links, Q1 is sorted now, which is great!
 * But I still cant use the same method for Q1 outside the loop. =/
 *  Thread Starter [paul-davis](https://wordpress.org/support/users/paul-davis/)
 * (@paul-davis)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/conditional-tag-problems-1/#post-1116828)
 * Ok, problem over. Due to a time constraint I’ve just used a general if/else statement
   bases on the URL.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Conditional Tag Problems’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [paul-davis](https://wordpress.org/support/users/paul-davis/)
 * Last activity: [16 years, 11 months ago](https://wordpress.org/support/topic/conditional-tag-problems-1/#post-1116828)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
