-
Notifications
You must be signed in to change notification settings - Fork 16
/
template-indicators.php
160 lines (101 loc) · 3.95 KB
/
template-indicators.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
<?php
/*
Template Name: Economic Indicators Template
*/
?>
<?php get_header(); ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php require_once('./simplepie/simplepie.inc');
// Set time zone (needs to be set before calling PHP date() or SimplePIE get_date())
date_default_timezone_set('America/New_York');
// We'll process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process.
$feed->set_feed_url( get_post_meta($post->ID, 'RSS_Feed', true) );
$feed->set_item_limit( 3 );
$feed->get_item_quantity( 3 );
$feed->enable_cache(false);
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
?>
<h2 class="sp-header">Economic Indicators</h2>
<div id="intro">
<h1 class="indicator-h1 chart-icon-pre"><?php the_title(); ?></h1>
<div class="box-updated">
<?php
$items = $feed->get_items( 0, 1 );
?>
<div>
<strong>Updated:</strong> <?php echo get_the_date( 'F j, Y' ); ?>
<!-- <strong>Updated:</strong> <?php echo $items[0]->get_date('F j, Y'); ?> -->
</div>
<?php
$next_update = get_post_meta($post->ID, 'Next_Update', true);
$next_update_is_future = strtotime($next_update) > time();
if ( $next_update && $next_update_is_future ): ?>
<div>
<strong>Next data release:</strong> <?php echo $next_update; ?>
</div>
<?php endif ?>
</div>
<div class="indicators-content">
<?php the_excerpt(); ?>
</div>
<?php endwhile; endif; ?>
<!-- <h3>Read the companion report on epi.org</h3> -->
<?php
/*
Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
*/
foreach ($feed->get_items( 0, 1 ) as $item):
?>
<!-- <h3>Updated <?php echo $item->get_date('F j, Y'); ?> | <em><a href="<?php echo $item->get_permalink(); ?>">Read the full report from EPI »</a></em></h3> -->
<div class="indicator-box">
<div class="item">
<!-- <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2> -->
<p>
<span class="ei-title"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></span>
<span class="ei-date">| <?php echo $item->get_date('g:i a, F j, Y'); ?></span>
<br>
<?php echo $item->get_description(); ?></p>
<!-- <p class="ei-readmore"><em><a href="<?php echo $item->get_permalink(); ?>">Read the full report from EPI »</a></em></p> -->
</div>
</div>
<div class="indicator-below">
Posted <?php echo $item->get_date('F j, Y'); ?> |
<em><a href="<?php echo $item->get_permalink(); ?>">Read the full report from EPI »</a></em>
</div>
<?php endforeach; ?>
<?php the_content(); ?>
<?php
$slug = get_queried_object()->post_name;
/* get_template_part( 'loop' ) only seems to work if the query is in $wp_query */
$temp_query = clone $wp_query;
// $wp_query = new WP_Query( "indicator=$slug&post_type=post&posts_per_page=-1" );
$wp_query = new WP_Query(array(
"indicator" => $slug,
"post_type" => array('post','chart'),
"posts_per_page" => -1,
));
get_template_part('loop', 'charts');
$wp_query = clone $temp_query;
?>
<!-- <h2>Previous <?php strtolower(the_title()); ?> reports</h2> -->
<h2>Previous reports</h2>
<?php
/*
Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
*/
foreach ($feed->get_items( 1, 3 ) as $item):
?>
<div class="item">
<h4><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>
<!-- <p><?php echo $item->get_description(); ?></p> -->
<p><small>Posted on <?php echo $item->get_date('F j, Y | g:i a'); ?></small></p>
</div>
<?php endforeach; ?>
</div></div>
<?php get_sidebar() ?>
<?php get_footer(); ?>