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.
Thread Starter
tyh
(@tyh)
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=('« <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>.
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.