Support » Fixing WordPress » next_post() from the Latest (Newest) Post??

  • (I had to set up a new account – messages from my existing one aren’t getting posted – what’s going on? Anyway, this is to test if I can post with another username. Also to provide the solution to my previous post.)
    I am having trouble with displaying Previous Post when on the first (oldest) page of the blog (there won’t be a previous post then, obviously)
    Vice versa on the latest post with ‘Next Post’.

    Right now, nothing is displayed if there is no previous/next page. This looks ugly, I think. (See

    Here is the solution that I want: When there is no previous post available, I want a non-hyperlink in the place where the link would normally go, I want to simply display a message saying: “Not available”

    To complicate matters, it appears that if you are on the first page and ask for the previous page, WP returns the name of the page you are on, instead of an empty string or null. Did I get that right?

    Finally got this code to work: hope it is of use to somebody! This (strangely) displays “Not available” when you ask for the previous post on the Oldest Post, or the Next Post from the newest post.

    $next_post = get_next_post();
    $prev_post = get_previous_post();
    <td id="previous_post"><?php if(get_permalink()!==get_permalink($prev_post->ID))
    {previous_post ('% <strong></strong> ', '');}
    else {echo "[Not Available]";}?></td>
    <td id="next_post"><?php if(get_permalink()!==get_permalink($next_post->ID))
    {next_post ('% <strong></strong> ', '');}
    else {echo "[Not Available]";}?>

  • The topic ‘next_post() from the Latest (Newest) Post??’ is closed to new replies.