Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $category = '';
- // for daily pagination within a category give $category a category ID
- // example: $category = 25;
- $join = '';
- $category_and = ' ';
- global $wpdb;
- if($category != '') {
- $join = "
- LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
- LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
- $category_and = "
- AND $wpdb->term_taxonomy.taxonomy = 'category'
- AND $wpdb->term_taxonomy.term_id = ".$category." ";
- }
- $query = "SELECT YEAR(post_date) AS `year`,
- MONTH(post_date) AS `month`,
- DAYOFMONTH(post_date) AS `dayofmonth`,
- count(ID) as posts
- FROM $wpdb->posts ".$join."
- WHERE post_type = 'post'
- AND post_status = 'publish' ".$category_and."
- GROUP BY YEAR(post_date),
- MONTH(post_date),
- DAYOFMONTH(post_date)
- ORDER BY post_date DESC";
- $arcresults = $wpdb->get_results($query);
- $category_query = ($category != '') ? '&cat='.$category : '';
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- if(!is_paged()){
- query_posts('posts_per_page=-1&year='.$arcresults[0]->year.'&monthnum='.$arcresults[0]->month.'&day='.$arcresults[0]->dayofmonth . $category_query);
- } else {
- $num = (int) $paged-1;
- query_posts('posts_per_page=-1&year='.$arcresults[$num]->year.'&monthnum='.$arcresults[$num]->month.'&day='.$arcresults[$num]->dayofmonth.$category_query);
- }
- // to show the next and previous links
- // can also be used after the loop
- if($paged >= 1 && ($paged < count($arcresults))){
- echo '<a href="' . get_permalink() . '?paged='.($paged+1).'">previous day link</a>';
- }
- if($paged == 2 ){
- echo '<a href="' . get_permalink() . '">next day link</a>';
- }
- if($paged > 2 ){
- echo '<a href="' . get_permalink() . '?paged='.($paged-1).'">next day link</a>';
- }
- // the loop
- // while ( have_posts() ) : the_post();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement