If there is no post in a category, how to hide it

If there is no post in category 19, how can I hide Products in html?

<div id='cssmenu'>
    <ul>
        <li class='active'><a href='#'><span>Home</span></a></li>
        <li class='has-sub'><a href='#'><span>Products</span></a>
            <ul >
                <?php query_posts('showposts=5&orderby=date&cat=19'); ?>
                <?php while (have_posts()) : the_post(); ?>
                <a href="<?php the_permalink(); ?>" ><li><?php the_meta(meta_key); ?><?php the_title(); ?> </li></a>
                <?php endwhile; ?>
            </ul>
        </li>
    </ul>
</div>

example menu is here : http://cssmenumaker.com/menu/modern-jquery-accordion-menu

Related posts

2 comments

  1. You can do something like this from server side

    <div id='cssmenu'>
      <ul>
        <li class='active'><a href='#'><span>Home</span></a>
        </li>
    
        <?php query_posts( 'showposts=5&orderby=date&cat=19'); if(have_posts()):?>
        <li class='has-sub'><a href='#'><span>Products</span></a>
          <ul>
            <?php while (have_posts()) : the_post(); ?>
            <a href="<?php the_permalink(); ?>">
              <li>
                <?php the_meta(meta_key); ?>
                <?php the_title(); ?>
              </li>
            </a>
            <?php endwhile; ?>
    
          </ul>
        </li>
        <?php endif;?>
      </ul>
    </div>
    

    Using jQuery check and filter the empty product item by count of li elements and hide them

    $('.has-sub').filter(function(){
        return $('ul li',this).length == 0;
    }).hide()
    
  2. try this,

    <?php query_posts('showposts=5&orderby=date&cat=19'); ?>
    <?php if(have_posts()) { //       <------ check before entering while.
             while (have_posts()) : the_post(); ?>
                <a href="<?php the_permalink(); ?>" ><li><?php the_meta(meta_key); ?><?php the_title(); ?> </li></a>
    <?php } endwhile; ?>
    

Comments are closed.