-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-country-posts.php
executable file
·123 lines (115 loc) · 3.65 KB
/
page-country-posts.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
<?php /* Template Name: Country posts */
get_header(); ?>
<div id="page-wpg">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div class="row">
<div class="col-md-8">
<h1 id="post-<?php the_ID(); ?>">
<?php the_title();?>
</h1>
</div>
<div class="col-md-4">
<div class="pull-right"><?php do_action('icl_language_selector'); ?></div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<?php the_content(); ?>
<h3>
Legend: <span class="label year-2013">2012</span> <span class="label year-2013">2013</span> <span class="label year-2014">2014</span> <span class="label year-2015">2015</span> <span class="label year-2016">2016</span> <span class="label year-2017">2017</span> <span class="label year-2018">2018</span> <span class="label year-2019">2019</span> <span class="label year-2020">2020</span> <span class="label year-2021">2021</span>
</h3>
</div>
</div>
<?php endwhile; endif; ?>
<?php //Posts about this Country
$countries = get_posts( array(
'post_type' => 'country',
'posts_per_page' => -1,
'suppress_filters' => 0, //to force the use of current language
'orderby' => 'title',
'order' => 'ASC',
));
$countCountries = count($countries);
$countposts = 0;
foreach($countries as $country) {
$posts = get_posts( array(
'post_type' => 'post',
'meta_key' => '_post_country',
'meta_value' => $country->ID,
'posts_per_page' => -1
));
$count = count($posts);
if ($posts) {
$countposts++;
if ( $countposts == 1 || $countposts % 4 == 1) { echo "<div class='row'>"; }
?>
<div class="col-md-3">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">
<?php _e('Updates from','globalrec'); ?>
<strong>
<a href='<?php echo $country->guid; ?>'>
<?php echo $country->post_title; ?>
</a>
</strong>
<span class="badge">
<?php echo $count; ?>
</span>
</div>
<ul class="list-group">
<?php
for ($i = 0; $i <= 2; $i++) {
if ( $i >= $count ) { } //to prevent crashing for countries with lesss than 2 posts
else {
$post = $posts[$i];
$published_year = get_the_date('Y');
$published_date = get_post_meta( $post->ID, '_gr_article-date', true );
echo '<li class="list-group-item year-' .$published_year . '"><a href="'.get_permalink($post->ID).'">'. $post->post_title .'<strong>'. get_the_date(' (m/Y)') .'</strong></a>';
if ( is_user_logged_in() ) {
echo ' <span class="label label-info">'. get_the_term_list( $post->ID, 'post-newsletter', ' ', ', ', '' ). '</span>';
}
echo '</li>';
}
} ?>
</ul>
</div>
</div>
<?php if ( $countposts % 4 == 0 || $countposts == 31 ){ echo "</div><!-- .row --><hr>";} ?>
<?php
} else { ?>
<?php }
wp_reset_query();
} ?>
<div class="row">
<h2><?php _e('No updates from','globalrec'); ?> <span class="badge">0</span></h2>
</div>
<div class="row">
<?php
foreach($countries as $country) {
$posts = get_posts( array(
'post_type' => 'post',
'meta_key' => '_post_country',
'meta_value' => $country->ID,
'posts_per_page' => -1
));
$count = count($posts);
if ($posts) {?>
<?php
} else { ?>
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">
<?php _e('No updates from','globalrec'); ?>
<strong><?php echo $country->post_title; ?></strong>
<span class="badge">0</span>
</div>
</div>
</div>
<?php }
wp_reset_query();
} ?>
</div>
</div>
</div>
<?php get_footer(); ?>