A WordPress plugin to paginate your posts by year, month or day.
This plugin provides an easy way to paginate posts by year, month or day in your theme’s template files. Use the native WordPress pagination functions to display the pagination links.
It’s likely your theme is already using these functions for normal pagination. If not, see if it works with your theme’s pagination or add them yourself.
To tell WordPress a page should be paginated by dates set the date_pagination_type query argument to 'yearly', 'monthly' or 'daily' in the pre_get_posts action. (See the examples below)
After that the posts will be paginated by date!
Note This plugin intentionally doesn’t do pagination for date archives. See this plugin to do just that.
Note: It’s recommended you create a child theme whenever you edit your theme template files.
Using dates in the pagination links
The WordPress pagination functions have labels similar as “Previous Page” and “Next Page” for the pagination links. If you would like to display dates instead use the label functions provided by this plugin.
To have the WordPress numerical pagination functions display dates instead of page numbers use the numerical pagination functions provided by this plugin instead.
Examples
These examples show you how to add Date Pagination to pages by seting the date_pagination_type query var.
Date pagination with pre_get_posts
You can set the type of date pagination to 'yearly', 'monthly' or 'daily' with the 'date_pagination_type' query variable.
Conditional tags let you choose where you want to use date pagination.
In this example we set the pagination to monthly on the home page. Use this example in your (child) theme’s functions.php file.
add_action( 'pre_get_posts', 'monthly_paginated_home_query' ); function monthly_paginated_home_query( $query ) { // not a wp-admin page and the query is for the main query if ( !is_admin() && $query->is_main_query() ) { // on the home page only if ( is_home() ) { // set the date pagination to 'monthly' $query->set('date_pagination_type', 'monthly'); // set other arguments here } } }
See this example loop for how you would use the WordPress pagination functions in your theme.
Getting date paginated posts with WP_Query
You can set the type of date pagination to 'yearly', 'monthly' or 'daily' with the 'date_pagination_type' argument.
In this example we set it to 'monthly'.
Note: Be aware that a custom query doesn’t update the main query and pagination. It’s only useful to get paginated posts. Use pre_get_posts instead.
<?php // Example arguments. $args = array( // set the date pagination to monthly 'date_pagination_type' => 'monthly', // 'yearly', 'monthly', 'daily' 'posts_per_page' => 10, 'paged' => 2, // get posts for the second page ); // The custom query. $the_query = new WP_Query( $args ); ?> <!-- The Loop --> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <!-- Your theme's loop code here --> <?php endwhile; ?>
For a more comprehensive example of a custom query and the loop using the WordPress pagination functions see this example.
Troubleshooting Steps
The same troubleshooting steps for WordPress pagination functions apply to this plugin.
Troubleshooting steps if you queried the loop with new WP_Query.
Did you set the paged parameter?
Is pagination broken on a static front page?
Did you reset the loops if there are multiple loops?
Did you add the $max_pages to the next_posts_link() function?
Did you add the total to the paginate_links() function?
Hi,
I have been looking for this type of plugin for a long time ….. think the idea of using dates for pagination is the way to go, especially for sites that generate a lot of content.
I am more a designer, with an appreciation of development … but this is a little bit past my skill set at the moment.
Are there any plans to release an out of the box plugin? Would really love to get this running on the sites I work with.
Many thanks in advance
David
Hi David,
Unfortunately this is as out of the box as it gets. It’s up to a theme where to display pagination, and what functions (or pagination plugins) are used. The plugin can’t know, filter or detect this. For the most part the plugin will be compatible with themes that use the native WordPress pagination functions.
Where do you encounter problems? On what pages do you want date pagination?
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
I’ve been looking for a plug-in like this for quite some time and
was hoping maybe you would have some experience with something like this.
Please let me know if you run into anything.
I truly enjoy reading your blog and I look forward to your new updates.
Is there any way this plugin can be altered so that the posts within each day can be sorted by a meta value? If I add a normal WP ‘orderby’=>’meta_value_num’ into this current, it spits out the days in order of votes
Hi Jordan Lejuwaan
Can you post the full query in a pastebin:
http://pastebin.com/
It seems that WordPress allows you to put two variables in the orderby parameter, first one being dominant, but if I just put ‘date’, then it orders by the timestamp, not by the day. So I will have to create another meta field that just stores the day of publishing instead of the timestamp. If you have a better solution, please let me know!
Hi keesiemeijer,
Good job with your plugin!
I am working on the blog section of this website
http://artistresidencecornwall.co.uk/whats-on/
to get the posts in monthly pagination.
I am using this plugin http://wordpress.org/support/plugin/the-future-is-now to have the possibility to publish post/events coming in next months.
Problem is that the first posts on the blog will be future dates.
Is there a way to use your plugin in order to display posts from the current month, when you land on the blog page?
I’d really appreciate your help,
if something sounds confusing I will post the code in codepen or pastebin
Thanks
–Simon
hello keesiemeijer,
I’m trying to use this pagination with the option set as daily.
using the code below though just gives me the current date for each link. They display the correct posts though, they just doesn’t display the correct date.
thoughts?
Hi RV
Do you use a WP_Query for your query in the template where you are using the label functions? Can you paste the content of the template in a pastebin and post a link to it here.
http://pastebin.com/
http://pastebin.com/mYkJ7a25
It shows current date on every page
Hi
Do you mean the current date from this function km_dp_get_current_date_label()? Or some other date? In what theme template file are you using this?
I meen it shows this date (today), 29-09-2015. I use it on custom page template
Does it display where the pagination should be shown? I see this
$now = date('d-m-Y',time());
. do you echo it out somewhere?Yes, it displays in pagination link. $now is only for compare dates. By the way, is it difficult to put an option ‘weekly’ to your plugin?
Great plugin! This is exactly what I’m looking for, however I’m wondering if there was a way I could get each page to show 2 month of posts instead of just one month. A sort of bi-monthly pagination.
Let me know if you think this is possible and how I could implement it.
Thanks,
Hi akramsideas
That can be done with some changes to the plugin. What kind of labels do you want for the next and previous links? With dates in them or just plain “Next posts” “Previous posts”
I’m thinking just Next Posts / Previous Posts
Replace the code in date-pagination.php with this: http://pastebin.com/raw.php?i=uaG2TBCh
It only works if you’re doing monthly pagination.
Thank you so much! This is prefect, it works just like I wanted. Great job!
I’m ran into an issue with the plugin the minute I posted my first 2015 post. It caused the previous month to suddenly add images and revisions as posts in the loop. It was really weird.
I’ve disabled the plugin at the moment, but was wondering if you might have an idea what could be causing the issue.
Thanks.
Hi akramsideas
I found the bug you mentioned. This only effects the revised plugin version with the two month pagination. Please try it with this version: http://pastebin.com/raw.php?i=AxfXjZnm
Thanks keesiemeijer, that works perfectly! As always this is an excellent plugin and does exactly what I need it to do.
Hey
This doesn’t work for me . basically i want the two month pagination showing posts of this month and next month on one page and future posts like Nov is going on January and Feb posts on next page. and say if December having no posts then it should show Nov and Jan posts on one page and Feb and march posts on next page pagination.
Pls reply ASAP.
I’ve got kind of an odd situation for you. My client is using this plugin to create archives by year, but they want the first year in the archive to be 2014, the next 2013, etc. I can do this by setting “order” to “DESC,” but then the posts themselves show up in descending order as well. Is there any way to have the pages go in descending order, but the posts in ascending? I.E. January would be first, February second, March third, but he pages would go 2014, 2013, 2012?
My theory is to create an array, reverse the array, and output, but I’m having some trouble with that getting the old dates rather than the new. Will report back as I progress…
Ah, just figured it out completely. Stored each post as a value in an array, reversed the arrays, then output the values using a foreach loop. Works perfectly 🙂
Hi Jacob Bearce,
I see you resolved it yourself 🙂
If I’ll find the time I will try and make this ordering more easy with the plugin itself.
Hi,
WordPress database error: [Column ‘ID’ in field list is ambiguous]
SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM ahf_posts JOIN ahf_icl_translations t ON ahf_posts.ID = t.element_id AND t.element_type = ‘post_event’ JOIN ahf_icl_languages l ON t.language_code=l.code AND l.active=1 WHERE 1=1 AND ahf_posts.post_type = ‘event’ AND (ahf_posts.post_status = ‘publish’ OR ahf_posts.post_status = ‘private’) AND t.language_code=’ur’ GROUP BY YEAR(post_date) ORDER BY ahf_posts.post_date DESC
i am receiving this error.. i am using wpml plugin…
Hi wpml
Sorry for the late reply. Can you try again with the new version.
hi keesiemeijer,
i am using new version.
I just updated the plugin to version 1. Are you using that version? Did the problem go away?
thank you. problem solved. updated to new version.
Thanks for letting me know 🙂
Hi, I’m trying using your plugin. It works ok on the main language, but it does not show anything for the secondary language. I’m using wpml and your plugin by shortcode in the single post page (single.php) via do_shortcode function. What can I do? Thanks
Hi emanuele,
This plugin doesn’t use shortcodes. I’think you’re referring to the Related Posts by Taxonomy plugin.
Can you please open a new topic in the WordPress forum.
https://wordpress.org/support/plugin/related-posts-by-taxonomy
sorry, I moved the post.
I love the Custom Post Type Date Archive, but is there a way for it to get along with this plugin, or for the CPT Date Archives to have daily pagination? Maybe Date Archives Pagination is for this purpose? It doesn’t seem to have much documentation so I didn’t know if it is a working plugin. I know this post is a little old, but the plugins are so perfect for what I’m working on. Thanks for any help you can offer!
Hi Kris
There is unfortunately no way to do this with this plugin. I will see if it can be done for the Custom Post Type Date Archive. Give me a few days. I’ll report back here
Hi again
I’ve created this plugin to paginate between custom post type date archives.
https://github.com/keesiemeijer/custom-post-type-date-archives-pagination
Let me know if it does what you want
Hi Kessie,
I found your plugin and it saves me lots of work.
I’m doing monthly pagination and I wonder if there’s any way to show the page for the current month, instead of future month, for my event post (custom post type)?
Thanks & Regards,
Harold
Hi Kessie, I have copy and pasted your “WP_Query loop with date pagination” example into a page template, but setting ‘date_pagination_type’ => ‘daily’ displays monthly instead of daily archives. Have I forgot something to make the ‘daily’ archives work? Thanks!
Thank you very much for the plugin! I have been using it with the ‘pre_get_posts‘ action, and it works perfectly!
But recently I try to use it with a custom query, it doesn’t work as expected. Here’s the code I used: https://www.bobz.co/filter-wordpress-posts-by-custom-taxonomy-term-with-ajax-and-pagination/, I used ‘date_pagination_type’ => ‘monthly’ in the “WP_Query” part (https://www.bobz.co/filter-wordpress-posts-by-custom-taxonomy-term-with-ajax-and-pagination/#step-3-2).
could you help to see what could be wrong? I am thinking if it is the action hooks “wp_ajax_do_filter_posts” and “wp_ajax_nopriv_do_filter_posts” there causing the problem.
Many many thanks in advance! ^^
Hello Kessie, thanks your plugin works great, I have it installed in a client website and we all are very happy with it.
The only request I received and I can’t accomplish is to list all the dates available and not just the one selected and the previous and next one.
Is it possible? could you please give me a hint?
Thanks !
Pietro
Hi pietro scarpa
Right now that’s not possible. I will update the plugin when I find the time
I’ve updated the plugin. Do you use a custom WP_Query or the pre_get_posts action to paginate?
Hello Kessie, that’s great thanks! I am using the pre_get_posts, how can I activate the new feature?
I’ve added the plugin to the WordPress repository as well.
https://wordpress.org/plugins/date-pagination/
There are also some new functions to list dates as in the WordPress numerical functions.
https://keesiemeijer.wordpress.com/date-pagination/functions/#numerical-pagination
To list all dates try it with this in your (child) theme’s template file
Hi Kessie.
I set the pagination type to ‘monthly’, and I have posts on pages separated by months.
How can I set a page/fix url to show the current month by default?
Thanks & Regards,
Harold
This tool allows you to know today’s date and availability of you in the Gregorian and Hijri, and offers you from: any day of the week – the day of the month – month – year.