-
Notifications
You must be signed in to change notification settings - Fork 1
/
archive-news.php
132 lines (110 loc) · 5.06 KB
/
archive-news.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
<?php
/**
* The template for displaying archive pages
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package Hale
* Theme Hale with GDS styles
* ©Crown Copyright
* Adapted from version from NHS Leadership Academy, Tony Blacker
* @version 2.0 February 2021
*/
get_header();
?>
<div id="primary" class="govuk-grid-column-full-from-desktop">
<h1 class="govuk-heading-xl">
News
</h1>
<?php if ( is_active_sidebar( 'news-listing' ) ) { ?>
<div id="hale-news-listing-widgets" class="hale-news_listing__widgets">
<?php dynamic_sidebar( 'news-listing' ); ?>
</div>
<?php } ?>
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-third">
<div class="news-archive-filter-section">
<p>Filter news by topic.</p>
<div class="news-archive-filter-form">
<form method="GET">
<label class="govuk-label" for="news-archive-filter-topic">Topic</label>
<?php
$dropdown_args = array(
"id" => "news-archive-filter-topic",
"class" => "govuk-select",
'show_option_all' => "All topics",
'depth' => 1,
'orderby' => 'name',
'order' => 'ASC',
'hierarchical' => 1,
);
wp_dropdown_categories($dropdown_args);
$disabled_subtopics = 'disabled="disabled"';
$selected_topic = get_query_var('cat');
$selected_sub_topic = get_query_var('subtopic');
$sub_topics = [];
if (is_numeric($selected_topic)) {
$sub_topics = get_terms(array(
'taxonomy' => 'category',
'parent' => $selected_topic
));
if (is_array($sub_topics) && !empty($sub_topics)) {
$disabled_subtopics = '';
}
}
?>
<label class="govuk-label" for="news-archive-filter-subtopic">Sub-topic</label>
<select name="subtopic" id="news-archive-filter-subtopic"
class="govuk-select" <?php echo $disabled_subtopics; ?>>
<option
value="0" <?php if ($selected_sub_topic == 0) { ?> selected="selected" <?php } ?> >
All Sub-topics
</option>
<?php if (is_array($sub_topics) && !empty($sub_topics)) {
foreach ($sub_topics as $sub_topic) {
?>
<option
value="<?php echo $sub_topic->term_id; ?>" <?php if ($selected_sub_topic == $sub_topic->term_id) { ?> selected="selected" <?php } ?> ><?php echo $sub_topic->name; ?></option>
<?php
}
}
?>
</select>
<button class="govuk-button">Filter</button>
</form>
</div>
</div>
</div>
<div class="govuk-grid-column-two-thirds">
<?php
if (have_posts()) {
$news_story_count = $GLOBALS['wp_query']->found_posts;
if($news_story_count > 1){
$news_story_count_text = $news_story_count . ' articles';
}
elseif($news_story_count == 1) {
$news_story_count_text = '1 article';
}
?>
<div class="news-story-count">
<?php echo $news_story_count_text; ?>
</div>
<div class="news-story-list">
<?php
while (have_posts()) {
the_post();
get_template_part( 'template-parts/content', 'news-list-item' );
} ?>
</div>
<?php
hale_archive_pagination('archive');
} else { ?>
<p><?php _e('No news articles found', 'hale'); ?></p>
<?php
}
?>
</div>
</div>
</div><!-- #primary -->
<?php
get_footer();