WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Next and Previous Posts URLs

[Resolved] Next and Previous Posts URLs

  • Is there any way to grab ONLY the URLs of the previous and next? The next_posts_link tag generates a button with it, I just need to grab the URL dynamically. This code also need to be in the headers so it would have to work outside the loop.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Many WordPress ‘template functions’ also have a corresponding ‘get_’ so in this case get_next_posts_link.

    See the line number 1113 area of wp-includes/link-template.php in version 2.7.1

    Thanks but it doesn’t seem to be working. Here is the code so you get an idea of what I’m trying to do.

    <link href="<?php get_next_posts_link(); ?>" id="arr-nav-right-link" />

    I want the link to the next posts populate the href. Is this possible?

    When I check the HTML source the href is empty. No link.

    <link href="" id="arr-nav-right-link" />

    I tried doing:

    <?php echo get_next_posts_link(); ?>

    But it returns the entire link with an . All I need is the URL.

    Look at the code in wp-includes/link-template.php looks like it eventually uses next_posts( $max_page, false ) at line 1099

    Michael thanks! That worked! Why isn’t this documented on the Template Tags page?

    Michael, this works for generating the pages urls, but on the a single post page it doesn’t generate a url for the next post. Is there a separate function for that?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Next and Previous Posts URLs’ is closed to new replies.