Advertisement
Guest User

Untitled

a guest
May 26th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. <?php if(is_category() or is_single() or is_tag()) { ?>
  2. <div class="widget pink fl100">
  3. <h3>Arkiv</h3>
  4. <div class="yearly-archive">
  5. <?php
  6. $current_category = single_cat_title("", false);
  7. $this_category = get_category($cat);
  8. $currentcat = $this_category->category_nicename; ?>
  9. <?php
  10. $oldest = get_posts( 'post_type=post&post_status=publish&posts_per_page=-1&order=ASC' );
  11. $oldest_date = $oldest[0]->post_date;
  12. $first_date = date('Y', strtotime($oldest_date));
  13. $todays_date = date('Y');
  14. $year_range = range($todays_date, $first_date);
  15. foreach ($year_range as $year) { ?>
  16. <div class="select-year<?php if($todays_date == $year) { ?> active<?php } ?>" data-year="<?php echo $year; ?>"
  17. ><?php echo $year; ?>
  18. </div><!-- .select-year -->
  19. <?php }
  20. foreach ($year_range as $year) { ?>
  21.  
  22. <div class="year"<?php if($todays_date == $year){?> style="display:block;"<?php }?> data-year="<?php echo $year; ?>">
  23.  
  24. <?php $args = array(
  25. 'posts_per_page' => -1,
  26. 'post_type' => 'post',
  27. 'post_status' => 'publish',
  28. 'year' => $year,
  29. 'category_name' => $currentcat
  30. );
  31.  
  32. $months = array(
  33. '01' => 'Januari',
  34. '02' => 'Februari',
  35. '03' => 'Mars',
  36. '04' => 'April',
  37. '05' => 'Maj',
  38. '06' => 'Juni',
  39. '07' => 'Juli',
  40. '08' => 'Augusti',
  41. '09' => 'September',
  42. '10' => 'Oktober',
  43. '11' => 'November',
  44. '12' => 'December');
  45. $mentioned_months = array();
  46. $first_month_done = false;
  47.  
  48. $yearly_posts = new WP_Query($args);
  49.  
  50. if($yearly_posts->have_posts()) {
  51. echo '<ul class="arkiv">';
  52. while($yearly_posts->have_posts()) {
  53. $yearly_posts->the_post();
  54. $month_num = get_the_time('m');
  55. $month = $months[$month_num];
  56.  
  57. if (!isset($mentioned_months[$month_num])) {
  58. $mentioned_months[$month_num] = 1;
  59. if ($first_month_done) { ?>
  60. </div> <!-- .year -->
  61. <? } ?>
  62.  
  63. <div class="toggle_month fl100" data-month="<?= $month_num ?>"><?= $month ?></div><!-- .toggle_month -->
  64. <div class="month_post_container fl100" data-month="<?= $month_num ?>">
  65. <?php
  66. $first_month_done = true;
  67. }
  68. ?>
  69. <div class="arkivpost">
  70. <span class="post_title">
  71. <a href="<?php the_permalink() ;?>">
  72. <?php $title = strip_tags(get_the_title()); if (strlen($title) >= 28) {
  73. echo mb_substr($title, 0,28, 'utf-8'); echo '...'; }
  74. else {
  75. echo $title; } ?>
  76. </a>
  77. </span>
  78. </div><!-- .arkivpost -->
  79. <?php }echo '</ul></div>';
  80. }
  81. }
  82. wp_reset_query(); wp_reset_postdata();
  83. ?>
  84. </div>
  85. <!-- .yearly-archive -->
  86. </div>
  87. <!-- .widget -->
  88. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement