-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-funding-opportunities.php
66 lines (65 loc) · 2.06 KB
/
page-funding-opportunities.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
<?php get_template_part('templates/page', 'header'); ?>
<?php
//always get them in order of title, then sort later using metadata if necessary
$args = array(
'posts_per_page' => -1,
'offset' => 0,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'funding',
'post_status' => 'publish',
);
?>
<?php if (!$posts_array = get_posts( $args )) : ?>
<div class="alert alert-warning">
<?php _e('Sorry, no funding opportunities found at this time.', 'roots'); ?>
</div>
<?php return; ?>
<?php endif; ?>
<?php
//How will they be displayed?
global $orderby;
global $divideby;
if ( $orderby = get_query_var( 'orderby' , 'title' ) )
if ( !in_array( $orderby , array( 'title' , 'sponsor' ) ) ) $orderby = 'title';
?>
<p class="h4 pull-left">
<a href="?orderby=title" class="btn btn-primary">Order Alphabetically</a>
<a href="?orderby=sponsor" class="btn btn-primary" alt="coming soon">Order by Agency</a>
<button class="btn btn-primary disabled">Order by Deadline</button>
</p>
<?php // START COLLAPSED - THERE ARE A LOT ?>
<p class="h4 pull-right">
<button class="btn btn-success" id="expand-all" data-group="funding-group">Expand All</button>
</p>
<div class="clearfix"> </div>
<div class="funding-group">
<?php
// show the posts, reordeed as necessary
switch ( $orderby ) {
case 'sponsor' :
foreach ( $posts_array as $post ) {
$sponsors[] = get_cfc_field( 'funding-details' , 'sponsor' , $post->ID ) ;
}
$all_sponsors = array_unique( $sponsors );
sort( $all_sponsors );
foreach ( $all_sponsors as $this_sponsor ) :
$first=true;
foreach ( $posts_array as $post ) :
if ( strcmp( get_cfc_field('funding-details' , 'sponsor' , $post->ID ) , $this_sponsor ) !== 0 ) continue;
setup_postdata( $post );
if ($first) echo "<h2>$this_sponsor</h2>";
$first=false;
get_template_part('templates/content', 'funding');
endforeach;
endforeach;
break;
case 'title':
default:
foreach ( $posts_array as $post ) : setup_postdata( $post );
get_template_part('templates/content', 'funding');
endforeach;
break;
}
?>
</div>