Advertisement
Guest User

Untitled

a guest
Feb 9th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?php
  2.  
  3. $dates_per_page = 4; // four dates to loop through (dates can have multiple posts)
  4. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  5. $all_posts = array();
  6.  
  7. $limit = ' LIMIT ' . (($paged -1) * $dates_per_page) . ',' . $dates_per_page ;
  8.  
  9.  
  10. global $wpdb;
  11. $where = "WHERE post_type = 'post' AND post_status = 'publish'";
  12. $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit";
  13.  
  14. $results = $wpdb->get_results($query);
  15. if($results) {
  16. $date_sorted = array();
  17. // loop through dates
  18. foreach ($results as $result){
  19. $date_posts = get_posts('year='.$result->year.'&monthnum='.$result->month.'&day='.$result->dayofmonth);
  20.  
  21. if($date_posts){
  22. // sort date posts by category
  23. foreach($date_posts as $post){
  24. setup_postdata( $post );
  25. $post_date = date('Ynj', strtotime( $post->post_date ));
  26. // change the category ID
  27. if(in_category(1)) {
  28. $date_sorted[$post_date]['first'][] = $post;
  29. } else {
  30. $date_sorted[$post_date]['last'][] = $post;
  31. }
  32. }
  33. }
  34. }
  35.  
  36. // make full array with category test on top
  37. foreach($date_sorted as $key => $date){
  38.  
  39. if(isset($date['first'])) {
  40. $all_posts = array_merge($all_posts, $date['first'] );
  41. }
  42. if(isset($date['last'])){
  43. $all_posts = array_merge($all_posts, $date['last'] );
  44. }
  45. }
  46.  
  47. } // end if($results)
  48. ?>
  49.  
  50. <?php
  51.  
  52. // the loop to display the posts
  53. if(!empty($all_posts)) : ?>
  54. <!-- todo: is make pagination functions -->
  55. <?php foreach($all_posts as $post) : setup_postdata($post); ?>
  56.  
  57. <!-- put your loop code here -->
  58. <?php the_title(); ?>
  59.  
  60. <?php endforeach; ?>
  61. <!-- todo: is make pagination functions -->
  62. <?php endif ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement