WordPress.org

Ready to get started?Download WordPress

Forums

Multiple if is_category (6 posts)

  1. Lee
    Member
    Posted 2 years ago #

    Ive an existing code but is too long as ive many categories (>30). If i were to use the below code, it seems too much. Is there a better way to do it?

    <?php if ( is_category('1') || is_category('2') || is_category('3') ) {
        echo 'hi';
    }
    ?>

    Basically i want all child categories within the main category, not the posts under the child categories. Thanks for your time.

  2. esmi
    Forum Moderator
    Posted 2 years ago #

  3. adpawl
    Member
    Posted 2 years ago #

    <?php
    if( is_category( array(9,2,3) ) ) { echo 'hi'; }
    ?>
  4. Lee
    Member
    Posted 2 years ago #

    dpawl: yup, thanks, but is there a way just to include just the child categories of the ancestor?
    esmi: im looking towards like the descendants categories, thanks

  5. adpawl
    Member
    Posted 2 years ago #

    @mylemonhead, http://codex.wordpress.org/Function_Reference/in_category ?
    I do not know exactly what you want to get.

  6. Lee
    Member
    Posted 2 years ago #

    thanks for replying adpawl, i stick to the above method you provided. cheers

Topic Closed

This topic has been closed to new replies.

About this Topic