Forums

[resolved] Conditional Tag Problems (4 posts)

  1. Paul Davis
    Member
    Posted 2 years ago #

    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(); ?>
  2. esmi
    Theme Diva & Mod
    Posted 2 years ago #

    Q1: Will this help?
    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

  3. Paul Davis
    Member
    Posted 2 years ago #

    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. =/

  4. Paul Davis
    Member
    Posted 2 years ago #

    Ok, problem over. Due to a time constraint I've just used a general if/else statement bases on the URL.

Topic Closed

This topic has been closed to new replies.

About this Topic