WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Next and Previous Posts URLs (7 posts)

  1. YOTS
    Member
    Posted 5 years ago #

    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.

  2. MichaelH
    Member
    Posted 5 years ago #

    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

  3. YOTS
    Member
    Posted 5 years ago #

    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" />

  4. YOTS
    Member
    Posted 5 years ago #

    I tried doing:

    <?php echo get_next_posts_link(); ?>

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

  5. MichaelH
    Member
    Posted 5 years ago #

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

  6. YOTS
    Member
    Posted 5 years ago #

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

  7. YOTS
    Member
    Posted 5 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic