-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpage-archives.php
63 lines (48 loc) · 1.72 KB
/
page-archives.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
* Template Name: Archives
*
* @package dangopress
*/
get_header();
# Create a new query
$new_query = new WP_Query('posts_per_page=-1&ignore_sticky_posts=1');
# Remember the last year and last month when iterate the year/month
$last_year = 0;
$last_mon = 0;
# Archives output html
$output = '';
while ($new_query->have_posts() ): $new_query->the_post();
# Get the current post year and month
$curr_year = get_the_time('Y');
$curr_mon = get_the_time('n');
# Add closing tags if found another month
if ($last_mon > 0 && ($last_mon != $curr_mon || $last_year != $curr_year))
$output .= '</div></div>';
# Stores the month
if ($last_mon != $curr_mon || $last_year != $curr_year) {
$last_mon = $curr_mon;
$output .= "<div class='year-archives' id='arti-$curr_year-$curr_mon'>";
$output .= "<h3 class='archive-title'>$curr_year-$curr_mon</h3>";
$output .= "<div class='month-archives archives-$curr_mon' id='arti-$curr_year-$curr_mon'>";
}
$output .= '<div class="archive-item"><a href="' . get_permalink() . '">';
$output .= '<span class="entry-time">' . get_the_time('n-d') . '</span>' . get_the_title();
$output .= '<span class="entry-comments">(' . get_comments_number('0', '1', '%') . ')</span>';
$output .= '</a></div>';
# Stores the year
if ($last_year != $curr_year) {
$last_year = $curr_year;
}
endwhile;
# Add closing tags
$output .= '</div></div>';
# Reset the post to current post
wp_reset_postdata();
?>
<article <?php post_class(); ?>>
<div class="entry-content">
<div id="archives-content"><?php echo $output; ?></div>
</div> <!-- end post-content -->
</article> <!-- end post -->
<?php get_footer(); ?>