Forums

[resolved] next_post_link not showing if no next post (4 posts)

  1. Alkorr
    Member
    Posted 10 months ago #

    Hi! I'm using <?php next_post_link(); ?> to show a link to the next post. But if there is no 'next post', how can I hide the HTML code I'm calling when there is a 'next post' so when there is no 'next post' nothing is showing at all?

    Thanks for your help! :)

  2. nsathees
    Member
    Posted 10 months ago #

    The question is not clear!
    if there is no next post then there won't be any thing to show.

  3. alchymyth
    The Sweeper
    Posted 10 months ago #

    maybe you can get some ideas here: http://www.transformationpowertools.com/wordpress/advanced-styling-of-the-prev-next-post-links

    generally:

    <?php if(get_adjacent_post(false, '', true)) {
    /*the previous post link and its html*/
    } else {
    /*either nothing or some spaceholder if no previous post*/
    } ; ?>
    
    <?php if(get_adjacent_post(false, '', false)) {
    /*the next post link and its html*/
    } else {
    /*either nothing or some spaceholder if no next post*/
    } ; ?>
  4. Alkorr
    Member
    Posted 10 months ago #

    Thank you very much alchymyth, this is exactly what I was looking for!

    My question may seemed unusual like nsathees pointed out, but you always manage to find a solution. You're a WP God, really :)

Reply

You must log in to post.

About this Topic