I’ve build a custom post type for a calendar and created a structure like this:
- 2012 (general parent)
- January-2012
- 1-January-2012
-2-January-2012 - …
- …
- 1-January-2012
- Februar-2012
- 1-February-2012
- 2-February-2012
- …
- …
- March-2012
- 1-March-2012
- 2-March-2012
- …
- …
- January-2012
If I am now on the side for the whole month, I want to display a link to the pages for the previous and next month.
example: January <– February –> March
I tried *get_previous_posts_link()* and get NULL,
then I set global $post and get NULL too.
Another question, is this in general the right way?
Maybe then I get the post data / link for 31st January?
I’m not sure if *get_previous_posts_link()* considers the hierarchy.
Well… I don’t think
get_previous_posts_link
would help you. It only return link to the previous set of posts within the current query. (seeprevious_posts_link
it prints this link, andget_previous_posts_link
returns it).And quote from Codex:
You could try with these plugins:
But I’m not sure if they will work correctly.
I always do it with my custom SQL query – it’s more efficient, because you don’t have to select all pages (and all info about these pages).
Of course you should write your own SQL query inside this function (it depends on your query params). You can write same function for previous page link.
PS. Probably it’s not the easiest way of doing it, but it is efficient and very customizable (if you know SQL).