WordPress.org

Ready to get started?Download WordPress

Forums

condiitonal `if` is not working right (3 posts)

  1. Xaliber
    Member
    Posted 1 year ago #

    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?

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    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 } ?>
  3. Xaliber
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic