Title: Problem with conditional posts navigation
Last modified: August 19, 2016

---

# Problem with conditional posts navigation

 *  [tactics](https://wordpress.org/support/users/tactics/)
 * (@tactics)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/problem-with-conditional-posts-navigation/)
 * I’ve searched the forums and almost have this figured out, but there’s still 
   a problem.
 * To prevent empty tags, I’m using a conditional statement to show or hide the 
   navigation to older/newer posts. The code I’m using in my theme is:
 *     ```
       <?php if (show_posts_nav()) : ?>
       <ul class="pagination">
       <li class="prevlink"><?php next_posts_link('Older Posts'); ?></li>
       <li class="nextlink"><?php previous_posts_link('Newer Posts'); ?></li>
       </ul>
       <?php endif; ?>
       ```
   
 * and in my functions I have:
 *     ```
       function show_posts_nav() {
       	global $wp_query;
       	return ($wp_query->max_num_pages > 1);
       }
       ```
   
 * If there’s no navigation necessary, there’s no ul. But if there’s only one link
   necessary, I still get an empty li tag.
 * Anyone know how to prevent that?

Viewing 1 replies (of 1 total)

 *  Thread Starter [tactics](https://wordpress.org/support/users/tactics/)
 * (@tactics)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/problem-with-conditional-posts-navigation/#post-953570)
 * Bueller? Anyone?

Viewing 1 replies (of 1 total)

The topic ‘Problem with conditional posts navigation’ is closed to new replies.

## Tags

 * [next_posts_link](https://wordpress.org/support/topic-tag/next_posts_link/)

 * 1 reply
 * 1 participant
 * Last reply from: [tactics](https://wordpress.org/support/users/tactics/)
 * Last activity: [17 years, 5 months ago](https://wordpress.org/support/topic/problem-with-conditional-posts-navigation/#post-953570)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
