global $my_exclude_categories, $my_exclude_categories_rss; $my_exclude_categories = array( 1, 3 ); $my_exclude_categories_rss = array( 1, 3 ); function next_week_link( $label = 'Next Week', $display = true ) { if ( $display ) echo get_week_link( $label, 'next' ); else return get_week_link( $label, 'next' ); } function previous_week_link( $label = 'Previous Week', $display = true ) { if ( $display ) echo get_week_link( $label, 'previous' ); else return get_week_link( $label, 'previous' ); } function get_week_link( $label, $next_or_previous = '' ) { $archive_month = get_this_week( $next_or_previous ); if ( $archive_month ) { $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; if ( $next_or_previous == 'next' ) { --$paged; } if ( $next_or_previous == 'previous' ) { ++$paged; } return '' . $label . ''; } return ''; } function get_this_week( $next_or_previous = '' ) { $arc_week = array(); $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; if ( $next_or_previous == 'next' && $paged == 1 ) { return $arc_week; } elseif ( $next_or_previous == 'next' && $paged > 1 ) { --$paged; } if ( $next_or_previous == 'previous' ) { ++$paged; } $limit = ( $paged > 1 ) ? ' LIMIT ' . ( $paged - 1 ) . ',1' : " LIMIT 1"; global $wpdb, $my_exclude_categories; $where = get_posts_by_author_sql( 'post' ); //$where = "WHERE post_type = 'post' AND post_status = 'publish'"; $join = ''; $order = 'DESC'; $week = _wp_mysql_week( '`post_date`' ); $tax_query = $tax_query = array( array( 'taxonomy' => 'category', 'terms' => $my_exclude_categories, 'operator' => 'NOT IN' ) ); $tax = get_tax_sql( $tax_query, $wpdb->posts, 'ID' ); $tax_where = $tax['where']; $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where $tax_where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit"; $arcresults = $wpdb->get_results( $query ); if ( $arcresults ) { $arc_w_last = ''; $arc_week = ''; if ( $arcresults ) { foreach ( (array)$arcresults as $arcresult ) { if ( $arcresult->week != $arc_w_last ) { $arc_year = $arcresult->yr; $arc_w_last = $arcresult->week; $arc_week = get_weekstartend( $arcresult->yyyymmdd, get_option( 'start_of_week' ) ); } } } } return $arc_week; } add_action( 'pre_get_posts', 'weekly_pagination' ); function weekly_pagination( $query ) { global $my_exclude_categories, $my_exclude_categories_rss; if ( !is_admin() && $query->is_main_query() ) { if ( is_home() ) { $query->set( 'nopaging', true ); $query->set( 'category__not_in', $my_exclude_categories ); add_filter( 'posts_where', 'new_posts_where' ); } if ( is_feed() ) { $query->set( 'category__not_in', $my_exclude_categories_rss ); } } } function new_posts_where( $where ) { if ( !is_admin() ) { global $wpdb; $week = get_this_week(); $start = $end = false; if ( $week ) { if ( $week['start'] ) { $start = date( 'Y-m-d H:i:s', $week['start'] ); } if ( $week['end'] ) { $end = date( 'Y-m-d H:i:s', $week['end'] ); } if ( $start && $end ) { $where.= " AND $wpdb->posts.post_date >= '$start' AND $wpdb->posts.post_date <= '$end'"; } } else { $where.= ' AND 1=0'; } } return $where; }