Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2. //function widget($args, $instance)
  3. $category_id = intval($instance['category_id']);
  4. $myposts = get_posts("numberposts=-1&offset=0&category=" . $category_id . "&orderby=date&order=DESC");
  5. $display_format = "F Y";
  6. $compare_format = "Ym";
  7. $previous_year_month_display = "";
  8. $previous_year_month_value = "";
  9. $count = 0;
  10. $interval = "month";
  11. $previous_year = "";
  12. $previous_month = "";
  13. $category_info = get_term_by("id", $category_id, "category");
  14. $category = $category_info->slug;
  15.  
  16. foreach($myposts as $post) {
  17.     $post_date = strtotime($post->post_date);
  18.     $current_year_month_display = date_i18n($display_format, $post_date);
  19.     $current_year_month_value = date($compare_format, $post_date);
  20.     $current_year = date("Y", $post_date);
  21.     $current_month = date("m", $post_date);
  22.  
  23.     if ($previous_year_month_value != $current_year_month_value) {
  24.         if ($count > 0) {
  25.             $url = $this->create_url($interval, $previous_year, $previous_month, $category_id, $category);
  26.             echo "<li><a href=\"". $url . "\">" . $previous_year_month_display . "</a>";
  27.                 echo  " (" . $count . ")";
  28.             echo "</li>";
  29.         }
  30.         $count = 0;
  31.     }
  32.     $count++;
  33.     $previous_year_month_display = $current_year_month_display;
  34.     $previous_year_month_value = $current_year_month_value;
  35.     $previous_year = $current_year;
  36.     $previous_month = $current_month;
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement