WordPress.org

Ready to get started?Download WordPress

Forums

Display next post link only if there is a next post (3 posts)

  1. Ryyo
    Member
    Posted 7 years ago #

    Howdy all,

    I've got a slight problem with my next post / previous post links. I want to wrap them in some generic markup, such as an
    <.li>, but when a user is on the most recent post, I don't want the "next post"

    <?php if (next_post_link()) { ?>
    <.li>Next: <?php next_post_link(); ?><.li>
    <?php } ?>

    Unfortunately this spits out the next post link once it gets to the if statement, rather than evaluating the if statement, then applying what's in between the brackets. Forgive my ignorance of php, but is there an easy way to accomplish this that I'm missing?

    Any help would be greatly appreciated!

    (forgive the "." before the li tags, the forum wants to parse those even if I encode them :-p )

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Try just having
    <?php next_post_link('<li>Next: %link</li>'); ?>
    instead. It's smart, if there's no next post, you don't get anything.

    Read up here to understand why this works: http://codex.wordpress.org/Template_Tags/next_post_link

  3. Ryyo
    Member
    Posted 7 years ago #

    Perfect!

    I had a feeling it was something simple like this.

    Thanks a bunch!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags