-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage-archives.php
More file actions
72 lines (51 loc) · 1.84 KB
/
page-archives.php
File metadata and controls
72 lines (51 loc) · 1.84 KB
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
64
65
66
67
68
69
70
71
72
<?php
/**
* Template Name: Archives
*/
get_header(); ?>
<div class="row">
<div class="<?php pipdig_left_or_right(); ?> content-area" role="main">
<ul class="years">
<?php
if ( false === ( $all_posts = get_transient( 'pipdig_archives_page' ) ) ) {
$all_posts = get_posts(array(
'posts_per_page' => -1, // to show all posts
'suppress_filters' => 0
));
set_transient( 'pipdig_archives_page', $all_posts, 24 * HOUR_IN_SECONDS );
}
// this variable will contain all the posts in a associative array
// with three levels, for every year, month and posts.
$ordered_posts = array();
foreach ($all_posts as $single) {
$year = mysql2date('Y', $single->post_date);
$month = mysql2date('F', $single->post_date);
// specifies the position of the current post
$ordered_posts[$year][$month][] = $single;
}
// iterates the years
foreach ($ordered_posts as $year => $months) { ?>
<li>
<h3><?php echo $year ?></h3>
<ul class="months">
<?php foreach ($months as $month => $posts ) { // iterates the moths ?>
<li>
<h3><?php printf("%s (%d)", $month, count($months[$month])) ?></h3>
<ul class="posts">
<?php foreach ($posts as $single ) { // iterates the posts ?>
<li>
<span class="page-archives-post-date"><?php echo mysql2date('D, jS', $single->post_date) ?>:</span> <a href="<?php echo get_permalink($single->ID); ?>"><?php echo get_the_title($single->ID); ?></a></li>
</li>
<?php } // ends foreach $posts ?>
</ul> <!-- ul.posts -->
</li>
<?php } // ends foreach for $months ?>
</ul> <!-- ul.months -->
</li> <?php
} // ends foreach for $ordered_posts
?>
</ul><!-- ul.years -->
</div><!-- .content-area -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>