This repository has been archived by the owner on Jul 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
template-archives.php
49 lines (39 loc) · 1.47 KB
/
template-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
<?php
/*
Template Name: Octopress Archives Template
*/
get_header(); ?>
<!-- Static Starts -->
<div id="main">
<div id="content">
<div>
<article role="article">
<header>
<h1 class="entry-title">Blog Archive</h1>
</header>
<div id="blog-archives">
<!--start -->
<?php
// get years that have posts
$years = $wpdb->get_results("SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY year DESC");
foreach ( $years as $year ) {
// get posts for each year
$posts_this_year = $wpdb->get_results("SELECT post_title,id FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = '" . $year->year . "'");
echo '<h2>' . $year->year . '</h2>';
foreach ( $posts_this_year as $post ) {
echo '<article><h1><a href="' . get_the_permalink($post->id) . '">' . $post->post_title . '</a></h1>';
echo "<time datetime=\"" . get_the_time('c', $post->id) . "\" pubdate><span class='month'>" . get_the_time('M', $post->id) . "</span> <span class='day'>" . get_the_time('d', $post->id) . "</span> <span class='year'>" . get_the_time('Y', $post->id) . "</span></time>";
echo '</article>';
}
}
?>
<!--end-->
</div><!-- blog archives -->
</article>
</div>
<aside class="sidebar thirds">
<?php dynamic_sidebar(); ?>
</aside>
</div><!-- #content -->
</div> <!-- content-->
<?php get_footer(); ?>