I currently use the following method to get a prev / next blog page link:
<?php previous_post_link( '%link', '%title' ); ?>
However this includes the outer element, name etc, I want just the link e.g. http://domain.com/blog/page/2
Is there a function that I’m not seeing to suit my requirements?
Clarification
- This is for the next blog page (not blog post)
- I only want the link, not the anchor element
Many thanks
Short answer:
get_previous_posts_page_link
is the function you want:Longer answer: follow the code.
previous_posts_link
callsget_previous_posts_link
.get_previous_posts_link
callsprevious_posts
to fetch the link URI itself.previous_posts
is just a little wrapper around the function you’re looking for:get_previous_posts_page_link
The function we want:
I included all of that to illustrate how you can go about finding answers by looking through the core. Tools like ack can help you get started:
In general, the WordPress is pretty good at making sure a function only does one thing. Tracing from broader functions (ala
previous_posts_link
and other template tags) back to more basic functions is usually a good way to learn some cool stuff and find your answer.Obviously you store this in an array, like
If you don’t want any other elements then you can add the following code to your theme’s page template instead. You links will then be assigned to $prevID and $nextID which you can do what you like with.
Similar to @liam-jay, but only getting one of the posts
I think this should work fine, untested though.
this is working:
For posterity. previous_posts() and next_posts() will do just that.