I have a wp_query set up to show events and I want to show the date if we have posts and if we do not I do not want to show the date.
Here is my code:
<?php $today = getdate(); $args = array( 'post_type' => 'post', 'category__not_in' => '-9', // When live, will need to add this parameter to all of the loop in this feedLoop.php - Do not forget to include this parameter as this function is needed!!! Cat No will change when live site is up and running!!! 'order' => 'ASC', 'post_status' => array( 'publish', 'future', ), 'date_query' => array( array( 'year' => $today['year'], 'month' => $today['mon'], 'day' => $today['mday'], ), ), ); $the_query = new WP_Query( $args ); ?> <h3><? echo date('l, F jS'); ?></h3> <!-- this is the date but I do not want it to echo out three time if there are three posts!! --> <?php if ( have_posts() ) :?> <? while ( $the_query->have_posts() ) :?> <? $the_query->the_post(); ?> <strong><em><?php the_time(); ?></em></strong> - <a href="<?php the_permalink(); ?>" class="strong"><?php the_title(); ?></a> <?php the_excerpt(); ?> <?php endwhile; else: ?> <p>There are no posts or pages here</p> <?php endif; ?> <?php wp_reset_query(); ?>
How can I query the arguments to see if there are posts and if so echoing out the date and hiding if not. Please someone put me out of my misery as I can not figure this out but it should be easy right?!!
Thanks for any help that I gain in advance!