-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-archive.php
207 lines (160 loc) · 9.75 KB
/
template-archive.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* Template name: Archive page template
* The template used for displaying the archive pages.
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<section id="post-<?php the_ID(); ?>" <?php post_class('archive-page entry-wrapper'); ?>>
<div class="container">
<div class="archive-top flex">
<header class="entry-header col col-xs-12 col-sm-10 offset-sm-1">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content col col-xs-12 col-sm-10 offset-sm-1 col-md-8 offset-md-2 col-xl-6 offset-xl-3">
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile;
// Edit link
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
esc_html__( 'Edit %s', 'regnsky' ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
),
'<span class="edit-link">',
'</span>'
);
?>
</div> <!-- .entry-content -->
</div> <!-- .flex -->
<div class="archive-categories flex">
<?php $recent_posts = 10; ?>
<h2 class="col col-xs-12">Seneste indlæg</h2>
<div class="archive-list module col col-xs-12 col-sm-6 col-lg-3">
<h4 class="text-brand-1">Opdagelser</h4>
<ul>
<?php
$post_args = array(
'category_name' => 'opdagelser',
'posts_per_page' => $recent_posts,
'offset' => 0
);
$posts = get_posts($post_args);
foreach($posts as $post) : ?>
<li class="h6">
<div class="meta">
<span class="h5 text-left">
<?php echo(mysql2date('j. F Y', $post->post_date)); ?>
</span>
</div>
<a class="link" href="<?php echo get_post_permalink( $post->post_ID); ?>">
<?php echo($post->post_title); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="archive-list module col col-xs-12 col-sm-6 col-lg-3">
<h4 class="text-brand-2">Livestemning</h4>
<ul>
<?php
$post_args = array(
'category_name' => 'livestemning',
'posts_per_page' => $recent_posts,
'offset' => 0
);
$posts = get_posts($post_args);
foreach($posts as $post) : ?>
<li class="h6">
<div class="meta">
<span class="h5 text-left">
<?php echo(mysql2date('j. F Y', $post->post_date)); ?>
</span>
</div>
<a class="link" href="<?php echo get_post_permalink( $post->post_ID); ?>">
<?php echo($post->post_title); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="archive-list module col col-xs-12 col-sm-6 col-lg-3">
<h4 class="text-brand-3">Features</h4>
<ul>
<?php
$post_args = array(
'category_name' => 'feature',
'posts_per_page' => $recent_posts,
'offset' => 0
);
$posts = get_posts($post_args);
foreach($posts as $post) : ?>
<li class="h6">
<div class="meta">
<span class="h5 text-left">
<?php echo(mysql2date('j. F Y', $post->post_date)); ?>
</span>
</div>
<a class="link" href="<?php echo get_post_permalink( $post->post_ID); ?>">
<?php echo($post->post_title); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="archive-list module col col-xs-12 col-sm-6 col-lg-3">
<h4 class="text-brand-4">Generelt</h4>
<ul>
<?php
$post_args = array(
'category_name' => 'generelt',
'posts_per_page' => $recent_posts,
'offset' => 0
);
$posts = get_posts($post_args);
foreach($posts as $post) : ?>
<li class="h6">
<div class="meta">
<span class="h5 text-left">
<?php echo(mysql2date('j. F Y', $post->post_date)); ?>
</span>
</div>
<a class="link" href="<?php echo get_post_permalink( $post->post_ID); ?>">
<?php echo($post->post_title); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="archive-years flex">
<?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 ID, post_title FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = '" . $year->year . "' " );
// reverse array of posts
krsort($posts_this_year);
echo '<h2 class="year-title year-' . $year->year . ' col col-xs-12">' . $year->year . '</h2>';
echo '<span class="year-amount col col-xs-12">' . count($posts_this_year) . ' indlæg' . '</span>';
echo '<div class="year-posts col col-xs-12"><ul>';
foreach ( $posts_this_year as $post ) {
$category_array = get_the_category($post->post_ID);
$category = $category_array[0];
$category_name = $category->cat_name;
echo '<li><a class="link h6 cat-' . strtoLower($category_name) . '" href="' . get_post_permalink($post->post_ID) . '">' . $post->post_title . '</a></li>';
}
echo '</div></ul>';
}
?>
</div>
</div> <!-- /.container -->
</section>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();