How i can create daily post pagination? I tried something like this, but server respond me 404 error:
<?php
// Global
global $wpdb;
// Sql query
$query = "SELECT DAYOFMONTH(post_date) AS 'dayofmonth',
count(ID) as posts
FROM $wpdb->posts
WHERE post_type = 'post'
AND post_status = 'publish'
GROUP BY DAYOFMONTH(post_date)
ORDER BY post_date DESC";
// Get results
$results = $wpdb->get_results($query);
// Paged
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// Is paged?
if(!is_paged()){
query_posts('posts_per_page=-1&day='.$results[0]->dayofmonth);
} else {
$num = (int) $paged-1;
query_posts('posts_per_page=-1&day='.$results[$num]->dayofmonth);
}
// Prev link
if($paged >= 1 && ($paged < count($results))){
echo '<a href="' . site_url() . '?paged='.($paged+1).'">Prev day</a>';
}
// Next day link
if($paged == 2 ){
echo '<a href="' . site_url() . '">Next day</a>';
}
// Next day link again
if($paged > 2 ){
echo '<a href="' . site_url() . '?paged='.($paged-1).'">Next day</a>';
}
?>
I would paginate by day, if selected day doesn't have posts then print for eg. "No posts on 12 september". If on selected posts are 3 posts then it displays 3 posts.
Aucun commentaire:
Enregistrer un commentaire