-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsingle-program.php
180 lines (141 loc) · 3.95 KB
/
single-program.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
<?php
// if parent
// display the program-index context
// likely to be only 4:
//
// Open Policy,
// Open Culture,
// Open Knowledge,
// Community
// if child
// display the program-page context
// likely to be many, and may include:
//
// [Open Policy]
// Copyright
// Better Internet
//
// [Open Culture]
// Open Heritage
// Open Creativity
//
// [Open Knowledge]
// Open Education
// Open Climate
// Open Science
// Open Research (OA)
// Open Journalism
//
// [Community]
// Global Network
// Learning & Training
// Licenses & Tools Stewardship
// Open Source Community
?>
<?php
// body class will need to be dynamic .program-index, .program-page
if ( get_field('nested_programs') ) {
$status = 'parent';
$class = 'program-index';
} else {
$status = 'child';
$class = 'program-page';
}
?>
<!-- this class will need to be dynamic program-index, program-page -->
<?php get_header('', array( 'body-classes' => $class) ); ?>
<main>
<?php while ( have_posts() ) : the_post(); ?>
<header>
<h1><?php the_title(); ?></h1>
<?php if(get_field('sub_heading')) : ?>
<h2><?php the_field('sub_heading'); ?></h2>
<?php endif; ?>
<p><?php the_field('introduction'); ?></p>
</header>
<?php the_content(); ?>
<?php
if ($status == 'parent') :
$children = get_field('nested_programs');
?>
<article class="projects">
<h2>On-going initiatives</h2>
<p><?php the_field('nested_programs_lead_in_copy'); ?></p>
<ul>
<?php
foreach ($children as $child) :
$permalink = get_permalink( $child->ID );
$title = get_the_title( $child->ID );
$excerpt = get_the_excerpt( $child->ID );
?>
<li>
<article class="project">
<h3><a href="<?php echo $permalink; ?>"><?php echo $title; ?></a></h3>
<p><?php echo wp_trim_words($excerpt, 8); ?></p>
</article>
</li>
<?php endforeach; ?>
</ul>
</article>
<?php endif; ?>
<?php
$queried_object = get_queried_object();
$categories = get_the_category( $post->ID );
$catIDs = '';
foreach( $categories as $category) {
$catIDs .= $category->cat_ID . ",";
}
$query = new WP_Query(array(
'cat' => $catIDs,
'post__not_in' => array($queried_object->ID),
'post_type' => 'post',
'posts_per_page' => 4,
//'paged' => $paged,
));
?>
<?php if ( $query->have_posts() ) : ?>
<article class="posts related">
<h2>Related posts</h2>
<ul>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<li>
<article class="post">
<header>
<h2><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php if ( get_field('authorship') ) : ?>
<span class="byline">by
<?php
$authors = get_field('authorship');
if( $authors ):
$i = 1;
$count = count($authors);
foreach( $authors as $author ):
$permalink = get_permalink( $author->ID );
$title = get_the_title( $author->ID );
$custom_field = get_field( 'field_name', $author->ID );
if ($i < $count) {
$separator = ',';
}
else {
$separator = '';
}
?>
<a href="<?php echo esc_url( $permalink ); ?>"><?php echo esc_html( $title ); ?></a><?php echo $separator; ?>
<?php $i++; ?>
<?php endforeach; ?>
<?php endif; ?>
</span>
<?php endif; ?>
<span class="categories">
<?php the_category(', ') ?>
</span>
</header>
</article>
</li>
<?php endwhile; ?>
</ul>
</article>
<?php endif; ?>
<?php endwhile; // end of the loop. ?>
</main>
<?php get_footer(); ?>