• I’ve removed articles from certain categories using the following code on my index.php:

    <?php if ( !(in_category('67') || in_category('37') || in_category('45') || in_category('47') || in_category('48') || in_category('39') || in_category('40') || in_category('41') || in_category('49') || in_category('50') || in_category('51') || in_category('52') || in_category('53') || in_category('54') || in_category('55') || in_category('56') || in_category('57') || in_category('58') || in_category('59') || in_category('60') || in_category('61') || in_category('62') || in_category('63') || in_category('64') || in_category('65') || in_category('66') && is_home()) ) { ?>

    It works fine to exclude all those categories.
    Too actually see the categories, i use category-XX.php templates, with a regular loop, which also works fine.

    The problem comes when i use if/else statements in my sidebar.php, to display subcategories of only the categories being used in category-XX.php templates.

    I have one sidebar.php and i use the following code:


    <?php if (in_category('37') ) { ?>
    <h2><?php _e('Categories'); ?></h2>
    <?php wp_list_cats('sort_column=name&optioncount=1&use_desc_for_title=0&child_of=37&hide_empty=0'); ?>

    <?php } else { ?>

    <?php if (in_category('49') ) { ?>

    <h2><?php _e('Categories'); ?></h2>
    <?php wp_list_cats('sort_column=name&optioncount=1&use_desc_for_title=0&child_of=49&hierarchical=1&hide_empty=0'); ?>

    <?php } else { ?>
    …………………… and so on until
    the final else, having all the categories (which would be any page that is not into one of the previous categories)


    <?php wp_list_cats('sort_column=name&optioncount=1&use_desc_for_title=0&hide_empty=1&exclude=37, 47, 48, 45, 39, 40, 41, 49, 56, 57, 58, 59, 60, 61, 63, 62, 64, 65, 66, 50, 51, 52, 53, 54, 55, 67, 2'); ?>

    The thing is, that when i randomly load my index.php, i get different “if” chosen. sometimes it picks the one i wrote for category 37, sometimes 49…
    and when i look at category-xx.php templates (actually, i use the category_name.php for them) it uses the incorrect category for the IF…

    how can i fix or debug this? is there any way i can output the categories being used in the current enviroment?

  • The topic ‘Problem with if/else’ is closed to new replies.