Advertisement
Guest User

Untitled

a guest
Mar 21st, 2012
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. $category = '';
  2. // for daily pagination within a category give $category a category ID
  3. // example: $category = 25;
  4.  
  5. $join = '';
  6. $category_and = ' ';
  7. global $wpdb;
  8.  
  9. if($category != '') {
  10.  
  11. $join = "
  12. LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
  13. LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
  14.  
  15. $category_and = "
  16. AND $wpdb->term_taxonomy.taxonomy = 'category'
  17. AND $wpdb->term_taxonomy.term_id = ".$category." ";
  18.  
  19. }
  20.  
  21. $query = "SELECT YEAR(post_date) AS `year`,
  22. MONTH(post_date) AS `month`,
  23. DAYOFMONTH(post_date) AS `dayofmonth`,
  24. count(ID) as posts
  25. FROM $wpdb->posts ".$join."
  26. WHERE post_type = 'post'
  27. AND post_status = 'publish' ".$category_and."
  28. GROUP BY YEAR(post_date),
  29. MONTH(post_date),
  30. DAYOFMONTH(post_date)
  31. ORDER BY post_date DESC";
  32.  
  33. $arcresults = $wpdb->get_results($query);
  34.  
  35. $category_query = ($category != '') ? '&cat='.$category : '';
  36.  
  37. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  38. if(!is_paged()){
  39.  
  40. query_posts('posts_per_page=-1&year='.$arcresults[0]->year.'&monthnum='.$arcresults[0]->month.'&day='.$arcresults[0]->dayofmonth . $category_query);
  41.  
  42. } else {
  43.  
  44. $num = (int) $paged-1;
  45. query_posts('posts_per_page=-1&year='.$arcresults[$num]->year.'&monthnum='.$arcresults[$num]->month.'&day='.$arcresults[$num]->dayofmonth.$category_query);
  46.  
  47. }
  48.  
  49. // to show the next and previous links
  50. // can also be used after the loop
  51. if($paged >= 1 && ($paged < count($arcresults))){
  52. echo '<a href="' . get_permalink() . '?paged='.($paged+1).'">previous day link</a>';
  53. }
  54.  
  55. if($paged == 2 ){
  56. echo '<a href="' . get_permalink() . '">next day link</a>';
  57. }
  58.  
  59. if($paged > 2 ){
  60. echo '<a href="' . get_permalink() . '?paged='.($paged-1).'">next day link</a>';
  61. }
  62.  
  63. // the loop
  64. // while ( have_posts() ) : the_post();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement