Support » Themes and Templates » next_post_link/previous_post_link

  • Can anyone help me with some php here using these tags (and I gather they are new and not yet documented in the codex)

    I want to determine if there IS a next or previous post in the navigation. Because the functions echo – any test I perform automatically displays the content which makes it hard to test to see if anything is being returned. is there any other test I can perform that if TRUE then calls one of these tags?


Viewing 5 replies - 1 through 5 (of 5 total)
  • skippy



    next_post_link() and previous_post_link() are defined in /wp-includes/template-functions-links.php. The very first line of next_post_link() is:
    $post = get_next_post($in_same_cat, $excluded_categories);

    This is a common theme with WordPress template tags / functions: there are two functions that do the same thing. One returns the result(s) and the other outputs the result(s). The returning functions are usually named get_*.
    [Note: there are a few exceptions to this, but not many.]

    So, if you do:
    $post = get_next_post();
    if ($post) { // do stuff }

    you should be set.

    skippy – you’re a marvel. Now I know this snippet of structure it might resolve a few other tweaks.
    Thanks very much – I’ll try it right away.

    Like a charm.
    Thanks very much

    Actually… yes it does work.
    But then I notice that the Archive page uses a variant. next_posts_link which is a different routine and doesn’t appear to have the same option as you gave me for the single page query. Can you by any chance offer a solution for this one? I would have liked to style it the same way!

    While on the subject, the ‘plural’ version s used in Archive and Search templates are phrased the opposite way to the single page version. I.e., the ‘Next’ function actually reteurns ‘previous’ posts as far as date order goes…

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘next_post_link/previous_post_link’ is closed to new replies.