1. <?php
  2.  
  3. function sslp_staff_member_listing_shortcode_func($atts) {
  4.     extract(shortcode_atts(array(
  5.       'single' => 'no',
  6.       'group' => '',
  7.       'wrap_class' => '',
  8.       'order' => 'ASC',
  9.       'orderby' => 'menu_order',
  10.     ), $atts));
  11.    
  12.     // Get Template and CSS
  13.    
  14.     $custom_html                = stripslashes_deep(get_option('_staff_listing_custom_html'));
  15.     $custom_css                 = stripslashes_deep(get_option('_staff_listing_custom_css'));
  16.     $default_tags               = get_option('_staff_listing_default_tags');
  17.     $default_formatted_tags     = get_option('_staff_listing_default_formatted_tags');
  18.     $output                     = '';
  19.     $group                      = strtolower($group);
  20.     $order                      = strtoupper($order);
  21.     $staff = '';
  22.    
  23.     $use_external_css           = get_option('_staff_listing_write_external_css');
  24.    
  25.     /**
  26.       * Set up our WP_Query
  27.       */
  28.    
  29.     $args = array( 'post_type' => 'staff-member', 'posts_per_page' => -1, 'orderby' => $orderby, 'post_status' => 'publish' );
  30.    
  31.     // Check user's 'order' value
  32.     if ($order != 'ASC' && $order != 'DESC') {
  33.         $order = 'ASC';
  34.     }
  35.    
  36.     // Set 'order' in our query args
  37.     $args['order'] = $order;
  38.     $args['staff-member-group'] = $group;
  39.    
  40.     $staff = new WP_Query( $args );
  41.    
  42.    
  43.     /**
  44.       * Set up our loop_markup
  45.       */
  46.    
  47.     $loop_markup = $loop_markup_reset = str_replace("[staff_loop]", "", substr($custom_html, strpos($custom_html, "[staff_loop]"), strpos($custom_html, "[/staff_loop]") - strpos($custom_html, "[staff_loop]")));
  48.    
  49.    
  50.     // Doing this so I can concatenate class names for current and possibly future use.
  51.     $staff_member_classes = $wrap_class;
  52.    
  53.     // Prepare to output styles if not using external style sheet
  54.     if ( $use_external_css == "no" ) {
  55.         $style_output = '<style>'.$custom_css.'</style>';
  56.     }
  57.    
  58.     $i = 0;
  59.    
  60.     if( $staff->have_posts() ) {
  61.    
  62.         $output .= '<div class="staff-member-listing '.$group.'">';
  63.        
  64.     while( $staff->have_posts() ) : $staff->the_post();
  65.        
  66.         if ($i == ($staff->found_posts)-1) {
  67.             $staff_member_classes .= " last";
  68.         }
  69.        
  70.         if ($i % 2) {
  71.             $output .= '<div class="staff-member odd '.$staff_member_classes.'">';
  72.         } else {
  73.             $output .= '<div class="staff-member even '.$staff_member_classes.'">';
  74.         }
  75.        
  76.         global $post;
  77.        
  78.         $custom     = get_post_custom();
  79.         $name       = get_the_title();
  80.         $name_slug  = basename(get_permalink());
  81.         $title      = $custom["_staff_member_title"][0];
  82.         $email      = $custom["_staff_member_email"][0];
  83.         $phone      = $custom["_staff_member_phone"][0];
  84.         $bio        = $custom["_staff_member_bio"][0];
  85.        
  86.        
  87.        
  88.         if(has_post_thumbnail()){
  89.            
  90.             $photo_url = wp_get_attachment_url( get_post_thumbnail_id() );
  91.             $photo = '<img class="staff-member-photo" src="'.$photo_url.'" alt = "'.$title.'">';
  92.         }else{
  93.             $photo_url = '';
  94.             $photo = '';
  95.         }
  96.        
  97.        
  98.         if (function_exists('wpautop')){
  99.             $bio_format = '<div class="staff-member-bio">'.wpautop($bio).'</div>';
  100.         }
  101.        
  102.        
  103.         $email_mailto = '<a class="staff-member-email" href="mailto:'.antispambot( $email ).'" title="Email '.$name.'">'.antispambot( $email ).'</a>';
  104.         $email_nolink = antispambot( $email );
  105.        
  106.         $accepted_single_tags = $default_tags;
  107.         $replace_single_values = array($name, $name_slug, $photo_url, $title, $email_nolink, $phone, $bio);
  108.    
  109.         $accepted_formatted_tags = $default_formatted_tags;
  110.         $replace_formatted_values = array('<h3 class="staff-member-name">'.$name.'</h3>', '<h4 class="staff-member-position">'.$title.'</h4>', $photo, $email_mailto, $bio_format);
  111.    
  112.         $loop_markup = str_replace($accepted_single_tags, $replace_single_values, $loop_markup);
  113.         $loop_markup = str_replace($accepted_formatted_tags, $replace_formatted_values, $loop_markup);
  114.    
  115.         $output .= $loop_markup;
  116.    
  117.         $loop_markup = $loop_markup_reset;
  118.        
  119.        
  120.        
  121.         $output .= '</div> <!-- Close staff-member -->';
  122.         $i += 1;
  123.    
  124.        
  125.     endwhile;
  126.    
  127.     $output .= "</div> <!-- Close staff-member-listing -->";
  128.     }
  129.    
  130.     wp_reset_query();
  131.    
  132.     $output = $style_output.$output;
  133.    
  134.     return $output;
  135. }
  136. add_shortcode('simple-staff-list', 'sslp_staff_member_listing_shortcode_func');
  137.  
  138. ?>