Archived topic
next/previous post navigation
8 replies · Started by Gerhard on May 11, 2021
Hello,
I have some trouble with my single post navigation!
.
My categories are years:
1992,1993,1994…
With the months as sub-categories:
Januar, Februar, März…
Take the following example for März 2010:
05.03.2010, 10.03.2010, 10.03.2010/2, 12.03.2010, 12.03.2010/2, 18.03.2010…
Now the previous-link of 10.03.2010 should point to 05.03.2010 and the next-link should go to 10.03.201/2.
The previous-link of 05.03.2010 should point to the next post chronologically that is 28.01.2010 because there are no posts in February.
Then the last post of lets say Dezember 2010 should have a next-link to the first post of Januar 2011 whereas the previos-link of the first post of Januar 2011 should go to the last post of Dezember 2010.
As you can see it’s rather tricky and I hope there is a solution and you can help me.
Greetings from Cologne
Gerhard
Hi there,
Can you try adding this filter? so the post stays within its category.
add_filter('generate_category_post_navigation','__return_true');
Let us know how it goes.
Hi Elvin,
after adding the filter now sometimes there is an order sometimes not. For example it jumps from post 10.03.2010/2 to 10.11.2010 instead of 12.03.2010?
Hi there,
It seems like this would need some sort of solution that sorted posts by category and sub-category together as one sorting parameter.. I'm not sure this is how the default WordPress post navigation was developed. It may require a custom solution, unfortunately.
Thank you Tom!
So I should perhaps better do the page without sub-categories (=months) but only with categories (= years)
Am I right thinking that WP would then sort my single posts(=german dates) correctly?
Greetings from Cologne
Gerhard
Hi Gerhard,
can't you simply adjust the date of the posts themselves, instead of using categories and tags? I'm asking because I do that all the time to create a chronologically correct archive. :)
Wordpress had date-based archives built-in, in other words you can use yoursite.something/2012/09/ to access the archive (even when your permalink structure is NOT using dates at all).
Grüsse aus San Diego :)
Alex.
GP uses the default way WordPress creates navigation links. It uses previous_post_link()
https://github.com/tomusborne/generatepress/blob/b60b853630da6d9015722da903e53c8064148b0a/inc/structure/post-meta.php#L58
and next_post_link()
https://github.com/tomusborne/generatepress/blob/b60b853630da6d9015722da903e53c8064148b0a/inc/structure/post-meta.php#L66
Now, the issue is, these core functions don't take arguments to specify how it gets sorted.
This means we go higher up and do things with get_adjacent_post()
Check this:
Hello,
I simply changed the single post's saving date which is now my chronological date(=entry-title) and now have the prev/next links in the correct order.
I guess my thoughts were too complicated...
Thanks to the great team of GP for help anyway!!
Greetings from Cologne
Gerhard
Nice one. Glad you got it sorted. :)