
Untitled
By: a guest on
Feb 9th, 2013 | syntax:
None | size: 1.90 KB | hits: 39 | expires: Never
<?php
$dates_per_page = 4; // four dates to loop through (dates can have multiple posts)
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$all_posts = array();
$limit = ' LIMIT ' . (($paged -1) * $dates_per_page) . ',' . $dates_per_page ;
global $wpdb;
$where = "WHERE post_type = 'post' AND post_status = 'publish'";
$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";
$results = $wpdb->get_results($query);
if($results) {
$date_sorted = array();
// loop through dates
foreach ($results as $result){
$date_posts = get_posts('year='.$result->year.'&monthnum='.$result->month.'&day='.$result->dayofmonth);
if($date_posts){
// sort date posts by category
foreach($date_posts as $post){
setup_postdata( $post );
$post_date = date('Ynj', strtotime( $post->post_date ));
// change the category ID
if(in_category(1)) {
$date_sorted[$post_date]['first'][] = $post;
} else {
$date_sorted[$post_date]['last'][] = $post;
}
}
}
}
// make full array with category test on top
foreach($date_sorted as $key => $date){
if(isset($date['first'])) {
$all_posts = array_merge($all_posts, $date['first'] );
}
if(isset($date['last'])){
$all_posts = array_merge($all_posts, $date['last'] );
}
}
} // end if($results)
?>
<?php
// the loop to display the posts
if(!empty($all_posts)) : ?>
<!-- todo: is make pagination functions -->
<?php foreach($all_posts as $post) : setup_postdata($post); ?>
<!-- put your loop code here -->
<?php the_title(); ?>
<?php endforeach; ?>
<!-- todo: is make pagination functions -->
<?php endif ?>