-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathione_shortcodes.php
135 lines (133 loc) · 4.88 KB
/
ione_shortcodes.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
<?php
/*
* Theme: IonE Mana Child
* Title: IonE Shortcodes
* Author: Jacob Grafenstein
* Author URI: https://github.com/Jake-Grafenstein
* Description: Shortcodes to display staff members and fellows based on their program or fellow type, respectively.
*/
function add_staff( $program ) {
$args = array(
'program'=>$program,
'post_type'=>'staff',
'posts_per_page'=> -1,
'post_status'=>'publish',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => 'order',
);
$my_query = new WP_Query($args);
if ($my_query) {
$output = '<ul class="people-list program-list">';
while ($my_query->have_posts()) {
$my_query->the_post();
$thumbnail = get_the_post_thumbnail($page->ID, array(200,230));
$permalink = get_the_permalink();
$title = get_the_title($page->ID);
$email = get_field('email', $page->ID);
$number = get_field('phone', $page->ID);
$twitter = get_field('twitter', $page->ID);
$output .= '<li class="individual-posts">';
if ($thumbnail) {
$output .= '<div class="entry-thumbnail"><a href="' . $permalink . '" rel="bookmark">' . $thumbnail . '</a></div>';
}
$output .= '<div class="entry-content-archive"><div class="employee_info"><a href="' . $permalink . '" rel="bookmark">' . $title . '</a><br />';
$output .= $title . '<br />';
if ($email) {
$output .= '<a href="mailto:' . $email . '">' . $email . '</a><br />';
}
if ($number) {
$my_number = str_split($number);
for ($i=0; $i <= strlen($number); $i++) {
if ($i == 3 || $i == 6) {
$output .= '-' . $my_number[$i];
}
else {
$output .= $my_number[$i];
}
}
$output .= '<br />';
}
if($twitter) {
$output .= '<a href="http://twitter.com/' . $twitter . '">@' . $twitter . '</a>';
}
$output .= '</div></div></li>';
}
$output .= '</ul>';
} else {
// no posts found
}
wp_reset_postdata();
return $output;
}
function add_fellow( $fellow_type ) {
$args = array(
'type'=>$fellow_type,
'post_type'=>'fellow',
'posts_per_page'=> -1,
'post_status'=>'publish',
'orderby' => 'title',
'order' => 'ASC',
);
$my_query = new WP_Query($args);
if ($my_query) :
$output = '<p>This is my fellow_type: ' . $fellow_type[type] . '</p>' . '<ul class="people-list">';
while ($my_query->have_posts()) :
$my_query->the_post();
$thumbnail = get_the_post_thumbnail($page->ID, array(200,230));
$title = get_the_title($page->ID);
$bio = get_field('bio', $page->ID);
$year = get_field('year', $page->ID);
$dept = get_field('department', $page->ID);
$college = get_field('college', $page->ID);
$post_objects = get_field('projects', $page->ID);
$output .= '<li class="individual-posts">';
if ($thumbnail) :
if ($bio) :
$output .= '<div class="entry-thumbnail"><a href="' . $bio . '" rel="bookmark">' . $thumbnail . '</a></div>';
$output .= '<div class="entry-content-archive"><div class="employee_info"><a href="' . $bio . '" rel="bookmark">' . $title . '</a><br />';
else :
$output .= '<div class="entry-thumbnail">' . $thumbnail . '</div>';
$output .= '<div class="entry-content-archive"><div class="employee_info">' . $title . '<br />';
endif;
else :
if ($bio) :
$output .= '<div class="entry-content-archive"><div class="employee_info"><a href="' . $bio . '" rel="bookmark">' . $title . '</a><br />';
else :
$output .= '<div class="entry-content-archive"><div class="employee_info">' . $title . '<br />';
endif;
endif;
//$output .= get_field('title', $page->ID) . '<br />';
if ($year) :
$output .= '<em>' . 'Fellow since ' . $year . '</em>' . '<br />';
endif;
$output .= '<strong>' . $dept . '</strong>' . '<br />';
$output .= $college . '<br />';
if ($fellow_type[type] == 'project-leads') :
if (!empty($post_objects)) :
$output .= '<hr class="project_line">';
$lastElement = end($post_objects);
endif;
if( $post_objects ):
$output .= 'Related Projects: ';
foreach( $post_objects as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post);
$output .= '<a href="' . get_the_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a>';
if ($post != $lastElement) :
$output .= '| ';
endif;
endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif;
endif;
$output .= '</div></li>';
endwhile;
$output .= '</ul>';
else :
// No Posts found
endif;
wp_reset_postdata();
return $output;
}
add_shortcode( 'add_staff', 'add_staff' );
add_shortcode( 'add_fellow', 'add_fellow');