Where to place ‘No posts’ else statement.
-
In the example below, how/where can I place ‘else echo ‘<p>(No posts match the criteria.)</p>’;’ code
<?php // Set the 'paged' parameter (use 'page' if the query is on a static front page). $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // Args for the query. $args = array( 'post_type' => 'post', 'posts_per_page' => 5, 'paged' => $paged ); // The query. $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { // Paginate (place between if and while). echo '<p>' . get_previous_posts_link('« Newer', $the_query->max_num_pages) . str_repeat(' ', 2) . get_next_posts_link('Older »', $the_query->max_num_pages) . '</p>' . "\n\n" ; echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } // end while echo '</ul>'; // Paginate (place between while and if). echo '<p>' . get_previous_posts_link('« Newer', $the_query->max_num_pages) . str_repeat(' ', 2) . get_next_posts_link('Older »', $the_query->max_num_pages) . '</p>' . "\n\n" ; } // end if // reset. wp_reset_postdata(); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Where to place ‘No posts’ else statement.’ is closed to new replies.