• Hi,
    is_category does not work for Sub-Category. If category B (ID =3) is under Category A (ID=2) then is_category(2) for a page that is in category B return false.

    Is there any workaround or another function that could used in such situation?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Let’s suppose you are talking about posts (since Pages don’t have categories). What is it exactly that you expect and is not happening?
    When you make a conditional statement based on a cat’s ID# – it doesn’t matter if it is a category or subcategory. Subcategories also have their own ID#.

    Thread Starter mamouri

    (@mamouri)

    Hi,
    Yeah, I meant posts, not pages. Actually I have a menu in my sidebar. One of my menu has sub-menus that represent sub-categories of a specified category (Category_Name=Essays, Category_ID=3) I want that this menu remain expanded while user are viewing each of sub-categories of category 3. Here is my code:

    <ul>
      <li><a href="<?php bloginfo('url')?>">Home</a></li>
      <li><a href="<?php bloginfo('url')?>/essays">Essays</a></li>
          <?php if (is_page('essays') || is_category(3)):?>
              <ol id="submenu">
                    <?php wp_list_categories('hide_empty=0&child_of=3&title_li=')?>
              </ol>
          <?php endif?>
      <li><a href="<?php bloginfo('url')?>/books">Books</a></li>
    </ul>

    As you see I use is_category. If user open category 5 that is actually is a sub-category of category 3 this condiciton (is_category(3)) is false. I need a function like (is_subcategoryof(3)) that check whether a category is child of a specied category or not.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘is_category and Sub-Category’ is closed to new replies.