Last active
August 29, 2015 14:10
-
-
Save cassler/303442795644d62e3c20 to your computer and use it in GitHub Desktop.
Team CPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'after_setup_theme', 'cb_custom_post_types' ); | |
function cb_custom_post_types() { | |
if ( ! class_exists( 'Super_Custom_Post_Type' ) ) | |
return; | |
$team = new Super_Custom_Post_Type( 'team', 'Team Member', 'Team Members' ); | |
$team->set_icon( 'group' ); | |
$team->add_meta_box( array( | |
'id' => 'hr-details', | |
'title' => 'HR Details', | |
'context' => 'advanced', | |
'fields' => array( | |
'job' => array('label' => 'Job Title'), | |
'school' => array('label' => 'Education'), | |
'phone' => array('label' => 'Phone Number'), | |
'email' => array('label' => 'Email Address') | |
) | |
) ); | |
$departments = new Super_Custom_Taxonomy( 'department', 'Department', 'Departments', 'cat'); | |
$departments->connect_post_types( $team ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Team CPT Display Shortcodes | |
* Outputs a collection of team members and relevant meta data by department | |
* @param 'cat' - pass the slug of a department taxonomy to define your scope. REQUIRED | |
* @author Darin Cassler | |
* @version 1.0 | |
* | |
**/ | |
if ( ! function_exists( 'cb_get_team_by_department' ) ): | |
function cb_get_team_by_department($atts) { | |
$a = shortcode_atts( array( | |
'cat' => '', | |
), $atts ); | |
$cat = $a['cat']; | |
$html = ''; | |
$category_id = get_term_by( 'slug', $cat, 'department' ); | |
$description = $category_id->description; | |
$department = $category_id->name; | |
$slug = $category_id->slug; | |
$staff_args = array( | |
'post_type' => 'team', | |
'posts_per_page' => -1, | |
'order' => 'ASC', | |
'offset' => 0, | |
'orderby' => 'menu_order date', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'department', | |
'field' => 'slug', | |
'terms' => $cat, | |
'operator' => 'IN', | |
'include_children' => 'false', | |
), | |
) | |
); | |
$staff_query = new WP_Query( $staff_args ); | |
if ($staff_query->have_posts()): | |
$html .= "<div class='staff-department' id='department-$slug'>"; | |
$html .= "<h3>$department</h3>"; | |
if ($description != null ) : | |
$html .= "<p class='staff-department-description lead'>$description</p>"; | |
endif; | |
$count = 0; | |
$html .= "<ul class='staff-department-list'>"; | |
while ($staff_query->have_posts()) : $staff_query->the_post(); setup_postdata($staff_query); | |
$id = get_the_ID(); | |
$content = get_post_field('post_content', $id); | |
$meta = ohana_get_meta(); | |
// print_r($staff_query); | |
$html .= '<a href="' . get_the_permalink($id) . '">'; | |
$html .= '<li class="staff-member">'; | |
$html .= '<h5>' . get_the_title($id) . '</h5>'; | |
$html .= '<div class="staff-member-description">'; | |
if ( has_post_thumbnail($id)) : | |
$html .= '<div class="staff-member-image">'; | |
$html .= get_the_post_thumbnail( $id, 'thumbnail', true ); | |
$html .= '</div>'; | |
endif; | |
if ( $meta['job'] != null ) { | |
$html .= '<h5 class="staff-member-title"><small>' . $meta['job'] . '</small></h5>'; | |
} | |
// $html .= apply_filters('the_excerpt', $content); | |
$count++; | |
$html .= '</div>'; | |
$html .= '</li>'; | |
$html .= '</a>'; | |
if ( $count === 2 || $count === 4 || $count === 6 || $count === 8 || $count === 10 || $count === 12 ) { | |
$html .= '<div class="clearfix hidden-sm hidden-md hidden-lg"></div>'; | |
} | |
if ( $count === 3 || $count === 6 || $count === 9 || $count === 12 ) { | |
$html .= '<div class="clearfix hidden-xs hidden-md hidden-lg"></div>'; | |
} | |
if ( $count === 4 || $count === 8 || $count === 12) { | |
$html .= '<div class="clearfix hidden-xs hidden-sm"></div>'; | |
} | |
endwhile; | |
$html .= '</ul></div>'; | |
endif; | |
return $html; | |
wp_reset_query(); | |
} | |
endif; | |
add_shortcode("show_staff", "cb_get_team_by_department"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment