WordPress.org

Ready to get started?Download WordPress

Forums

'Raw' link to previous/next post (5 posts)

  1. tyh
    Member
    Posted 9 years ago #

    Hi,

    Is there any way or any tags that can return the 'raw' link to previous/next posts? eg. http://mysite.com/post/

    Have tried various tags, but they all return .

    Am trying to put the previous/next post link in javascript.

  2. skippy
    Member
    Posted 9 years ago #

    get_previous_post() and get_next_post() are defined in wp-includes/template-functions-links.php.

    You could use these functions, and also review previous_post_link() and next_post_link() (both of which echo instead of return) for how to obtain the links you need.

  3. tyh
    Member
    Posted 9 years ago #

    Want to put the link in the code location.href=(link)

    Using get_previous_post() gives
    location.href=('')

    while using previous_post_link() gives
    location.href=('&laquo; <a href="http://mysite.com/link">Post title</a>')

    Have tried putting 'echo get_previous_post()' which gives location.href=('Object')

    Any ideas?

    n.b. In above post,
    Have tried various tags, but they all return .

    should be
    Have tried various tags, but they all return <a href="http://mysite.com/link"></a>.

  4. skippy
    Member
    Posted 9 years ago #

    get_previous_post() returns an actual post object. With this object, you could then feed the previous post's ID to get_permalink().

    Also take a look at the arguments accepted by previous_post_link() and next_post_link() for ways to control and format the link.

  5. roterhund
    Member
    Posted 9 years ago #

    Check out these wp-codex pages, you might find a solution for what you want to do:
    http://codex.wordpress.org/Template_Tags/previous_post
    http://codex.wordpress.org/Template_Tags/next_post

Topic Closed

This topic has been closed to new replies.

About this Topic