Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //function widget($args, $instance)
- $category_id = intval($instance['category_id']);
- $myposts = get_posts("numberposts=-1&offset=0&category=" . $category_id . "&orderby=date&order=DESC");
- $display_format = "F Y";
- $compare_format = "Ym";
- $previous_year_month_display = "";
- $previous_year_month_value = "";
- $count = 0;
- $interval = "month";
- $previous_year = "";
- $previous_month = "";
- $category_info = get_term_by("id", $category_id, "category");
- $category = $category_info->slug;
- foreach($myposts as $post) {
- $post_date = strtotime($post->post_date);
- $current_year_month_display = date_i18n($display_format, $post_date);
- $current_year_month_value = date($compare_format, $post_date);
- $current_year = date("Y", $post_date);
- $current_month = date("m", $post_date);
- if ($previous_year_month_value != $current_year_month_value) {
- if ($count > 0) {
- $url = $this->create_url($interval, $previous_year, $previous_month, $category_id, $category);
- echo "<li><a href=\"". $url . "\">" . $previous_year_month_display . "</a>";
- echo " (" . $count . ")";
- echo "</li>";
- }
- $count = 0;
- }
- $count++;
- $previous_year_month_display = $current_year_month_display;
- $previous_year_month_value = $current_year_month_value;
- $previous_year = $current_year;
- $previous_month = $current_month;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement