Support » Fixing WordPress » if/ else/ categories

  • Hi Guys,

    I have a bunch of conditionals within a navbar and just need this last piece for it to work perfectly.

    What I have is:
    Category1
    link1
    link2
    link3

    Category2
    link4
    link5

    Category3
    link6
    link7

    Etc

    I’m using a very basic javascript to show/ hide each child menu

    Now … I need to do a if/ else to show 1 line:

    <?php if ( is_category('1') ) {
    echo '<ul class="show" id="packaging">';
    } else {
    echo '<ul class="hide" id="packaging">';
    }
    ?>

    This works fine on the first child menu but not on any of the others.

    Any reason why not?

    I can PM the URL if need be.

    TIA

Viewing 2 replies - 1 through 2 (of 2 total)
  • You mean like:

    <?php if ( is_category('1') || is_category('2') || is_category('3') ) {

    Thread Starter Lee Rickler

    (@bigbadboy)

    Thanks Michael but no joy with that.

    I think my problem is that I am trying to call a sub (child) category separate from a parent category:
    Parent Category 1

    <?php if ( is_category('2') ) {
    echo '<ul class="show" id="childcat1">';
    } else {
    echo '<ul class="hide" id="childcat1">';
    }
    ?>
        <?php
    $posts_li = new WP_Query(array('category__and'=>array(2),'showposts'=>-1,'orderby'=>title,'order'=>ASC));
    ?>
        <?php while( $posts_li->have_posts() ) : $posts_li->the_post(); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>

    etc

    and repeat for each child category.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘if/ else/ categories’ is closed to new replies.