I am trying to create a left nav menu that contains a couple of different taxonomy lists of a custom post type. For example, the left menu might look like this...
<h2>New Stuff</h2>
<ul>
<li>Item 3</li>
<li>Item 4</li>
</ul>
<h2>Old Stuff</h2>
<ul>
<li>Item 2</li>
<li>Item 1</li>
</ul>
Below is the code I currently have in my sidebars template...
<h2>New Stuff</h2>
<ul>
<?php
$args = array(
'post_type' => 'stuff',
'taxonomy' => 'stuff-type',
'term' => 'new-stuff',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' =>-1
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</ul>
<h2>Old Stuff</h2>
<ul>
<?php
$args = array(
'post_type' => 'stuff',
'taxonomy' => 'stuff-type',
'term' => 'old-stuff',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' =>-1
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</ul>
This all works fine expect that I need the h2 and ul tags to not appear if there are no posts assigned to the taxonomy. How can I get the opening h2 title and ul wrappers somehow in the WordPress loop (just before and after), leaving the else/endif statement to print nothing (printing nothing if there are no posts for that taxonomy)?