• I have this on my header.php

    <?php if ( is_home() || is_front_page() ) { ?>
    
    			<?php } elseif ( is_category_or_sub('gamenews') || has_category('gamenews') ) { ?>
    			<ul id="sections">
    				<li><!-- stuff X here --></li>
    			</ul><!-- #sections -->
    			<?php } elseif ( is_category_or_sub('hobbynews') || has_category('hobbynews') ) { ?>
    			<ul id="sections">
    				<li><!-- stuff Y here --></li>
    			</ul><!-- #sections -->
    			<?php } ?>

    It is supposed to show different stuff on different page. If it’s on homepage (is_home), it shows nothing. If it’s on category gamenews or its children (is_category_or_sub, it’s a custom function), it shows stuff X. If it’s on category hobbynews or its children, it shows stuff Y.

    The problem lies on the last elseif (the one on hobbynews). It won’t show the stuff Y as I expect it to be. Instead, it shows stuff X which is supposed to only appear on gamenews category.

    Why is it happening?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You don’t have anything specified within that conditional statement:

    <?php if ( is_home() || is_front_page() ) { ?>
    
     // Nothing Specified 
    
    <?php } elseif ( is_category_or_sub('gamenews') || has_category('gamenews') ) { ?>
    <ul id="sections">
    	<li><!-- stuff X here --></li>
    </ul><!-- #sections -->
    <?php } elseif ( is_category_or_sub('hobbynews') || has_category('hobbynews') ) { ?>
    <ul id="sections">
    	<li><!-- stuff Y here --></li>
    </ul><!-- #sections -->
    <?php } ?>

    Thread Starter Xaliber

    (@xaliber)

    Yeah, I know if it’s on home page.

    Like I said, the problem is on the category/children of hobbynews. Nothing shows when I open the category hobbynews, where supposedly it should have shown Stuff Y. It does not show anything; instead, it shows Stuff X.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘condiitonal `if` is not working right’ is closed to new replies.