Title: Conditional tag for next/previous posts?
Last modified: August 18, 2016

---

# Conditional tag for next/previous posts?

 *  [fekketcantenel](https://wordpress.org/support/users/fekketcantenel/)
 * (@fekketcantenel)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-tag-for-nextprevious-posts/)
 * I’m not very good with PHP, so I can’t ascertain it from the source itself. Can
   someone please tell me: what should I use as an ‘if’ when checking to see if 
   there’s a previous/next post?
 * This is something like the code I’d like to use:
 * `
    <?php if(!$post->post_previous) { next_post('%','Next &raquo;', 'no'); } else
   if(!$post->post_next) { previous_post('%','&laquo; Previous', 'no'); } else {
   previous_post('%','&laquo; Previous', 'no'); :; next_post('%','Next &raquo;','
   no'); } ?>
 * Pretty much, if there is a previous post but no next post, show only the previous;
   if there’s a next but no previous, show only the next; if there are both next
   and previous posts, show both with a : seperator. I hope this is clear enough,
   because I’m afraid I’ve muddled the question up too much.

Viewing 1 replies (of 1 total)

 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-tag-for-nextprevious-posts/#post-317573)
 * `next_post` and `previous_post` are used on **single** post view (=single.php)
   and they do that by default:
    [Template_Tags/next_post](http://codex.wordpress.org/Template_Tags/next_post)

Viewing 1 replies (of 1 total)

The topic ‘Conditional tag for next/previous posts?’ is closed to new replies.

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [moshu](https://wordpress.org/support/users/moshu/)
 * Last activity: [20 years, 5 months ago](https://wordpress.org/support/topic/conditional-tag-for-nextprevious-posts/#post-317573)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
