WordPress.org

Ready to get started?Download WordPress

Forums

if/ else/ categories (3 posts)

  1. Lee Rickler
    Member
    Posted 5 years ago #

    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

  2. MichaelH
    Member
    Posted 5 years ago #

    You mean like:

    <?php if ( is_category('1') || is_category('2') || is_category('3') ) {
  3. Lee Rickler
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic