WordPress.org

Ready to get started?Download WordPress

Forums

Category not validating conditions... (2 posts)

  1. jabbamonkey
    Member
    Posted 2 years ago #

    I have the following code:

    if (is_category() || is_page('finds') || is_page('family')) {
    if(is_category('finds') || in_category('finds') || is_page('finds')) {
       $maincat = 'Finds';
    } elseif(is_category('family') || in_category('family') || is_page('family')) {
       $maincat = 'Family'; }
    $maincat_nicename = strtolower($maincat);
    echo '<h2> CatName:'.$maincat.' CatNiceName:'.$maincat_nicename.'<br /></h2>';
    }

    Basically, the code checks to see if the page is a CATEGORY or a specific PAGE. Then, depending on the category or page name, it sets a variable ($maincat). Either the page is a PAGE or it IS a CATEGORY or is IN a CATEGORY (for example: it is either the category called 'Find', or it is IN a category called 'Find').

    Most of the time, this code works fine. But, there is one category called 'School-Age' that is located in the 'Family' category that doesn't work. When I go to that category page for 'school-age', it does NOT set the variable $maincat. It should satisfy the condition:

    in_category('fort')
    (because it is IN the 'family' category)

    and it should do the following:

    $maincat = 'Family';

    But, it is NOT echoing a value for $maincat.

    Please help! I double-checked the administration and there is definitely a category in FAMILY called SCHOOL-AGE. Also, there are other categories that work fine.

  2. jabbamonkey
    Member
    Posted 2 years ago #

    I just checked something else... So, I go to the page...
    /category/family/school-age/

    And I wrote this at the top of the page...

    if ( in_category('family') ) {
    	echo '<h3>IN family category</h3>';
    } else {
    	echo '<h3>NOT in family category</h3>';
    }

    And it is outputting... 'NOT in family category'

    Can anyone explain why this is happening? It's obviously IN the family category...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.