Advertisement
brett

/public/partials/simple-staff-list-shortcode-display.php

Jan 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.43 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Provide a public-facing view for the plugin
  5.  *
  6.  * This file is used to markup the public-facing aspects of the plugin.
  7.  *
  8.  * @link       http://www.brettshumaker.com
  9.  * @since      1.17
  10.  *
  11.  * @package    Simple_Staff_List
  12.  * @subpackage Simple_Staff_List/public/partials
  13.  */
  14.  
  15.     global $sslp_sc_output;
  16.  
  17.     $atts = $this->simple_staff_list_shortcode_atts;
  18.     $single = $atts['single'];
  19.     $group = $atts['group'];
  20.     $wrap_class = $atts['wrap_class'];
  21.     $order = $atts['order'];
  22.     $image_size = $atts['image_size'];
  23.    
  24.     // Get Template and CSS
  25.    
  26.     $custom_html                = stripslashes_deep(get_option('_staff_listing_custom_html'));
  27.     $custom_css                 = stripslashes_deep(get_option('_staff_listing_custom_css'));
  28.     $default_tags               = get_option('_staff_listing_default_tags');
  29.     $default_formatted_tags     = get_option('_staff_listing_default_formatted_tags');
  30.     $output                     = '';
  31.     $group                      = strtolower($group);
  32.     $order                      = strtoupper($order);
  33.     $staff = '';
  34.    
  35.     $use_external_css           = get_option('_staff_listing_write_external_css');
  36.    
  37.     /**
  38.       * Set up our WP_Query
  39.       */
  40.    
  41.     $args = array( 'post_type' => 'staff-member', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'post_status' => 'publish' );
  42.    
  43.     // Check user's 'order' value
  44.     if ($order != 'ASC' && $order != 'DESC') {
  45.         $order = 'ASC';
  46.     }
  47.    
  48.     // Set 'order' in our query args
  49.     $args['order'] = $order;
  50.     $args['staff-member-group'] = $group;
  51.    
  52.     $staff = new WP_Query( $args );
  53.    
  54.     /**
  55.       * Set up our loop_markup
  56.       */
  57.    
  58.     $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]")));
  59.    
  60.    
  61.     // Doing this so I can concatenate class names for current and possibly future use.
  62.     $staff_member_classes = $wrap_class;
  63.    
  64.     // Prepare to output styles if not using external style sheet
  65.     if ( $use_external_css == "no" ) {
  66.         $style_output = '<style>'.$custom_css.'</style>';
  67.     } else { $style_output = ''; }
  68.    
  69.     $i = 0;
  70.    
  71.     if( $staff->have_posts() ) {
  72.    
  73.         $output .= '<div class="staff-member-listing '.$group.'">';
  74.        
  75.     while( $staff->have_posts() ) : $staff->the_post();
  76.        
  77.         if ($i == ($staff->found_posts)-1) {
  78.             $staff_member_classes .= " last";
  79.         }
  80.        
  81.         if ($i % 2) {
  82.             $output .= '<div class="staff-member odd '.$staff_member_classes.'">';
  83.         } else {
  84.             $output .= '<div class="staff-member even '.$staff_member_classes.'">';
  85.         }
  86.        
  87.         global $post;
  88.        
  89.         $custom     = get_post_custom();
  90.         $name       = get_the_title();
  91.         $name_slug  = basename(get_permalink());
  92.         $title      = $custom["_staff_member_title"][0];
  93.         $email      = $custom["_staff_member_email"][0];
  94.         $phone      = $custom["_staff_member_phone"][0];
  95.         $bio        = $custom["_staff_member_bio"][0];
  96.         $fb_url     = $custom["_staff_member_fb"][0];
  97.         $tw_url     = 'http://www.twitter.com/' . $custom["_staff_member_tw"][0];
  98.        
  99.        
  100.        
  101.         if(has_post_thumbnail()){
  102.             $image_obj = wp_get_attachment_image_src(get_post_thumbnail_id(), $image_size, false);
  103.             $src = $image_obj[0];
  104.            
  105.             $photo_url = $src;
  106.             $photo = '<img class="staff-member-photo" src="'.$photo_url.'" alt = "'.$title.'">';
  107.         }else{
  108.             $photo_url = '';
  109.             $photo = '';
  110.         }
  111.        
  112.        
  113.         if (function_exists('wpautop')){
  114.             $bio_format = '<div class="staff-member-bio">'.wpautop($bio).'</div>';
  115.         }
  116.        
  117.        
  118.         $email_mailto = '<a class="staff-member-email" href="mailto:'.antispambot( $email ).'" title="Email '.$name.'">'.antispambot( $email ).'</a>';
  119.         $email_nolink = antispambot( $email );
  120.        
  121.         $accepted_single_tags = $default_tags;
  122.         $replace_single_values = array($name, $name_slug, $photo_url, $title, $email_nolink, $phone, $bio, $fb_url, $tw_url);
  123.    
  124.         $accepted_formatted_tags = $default_formatted_tags;
  125.         $replace_formatted_values = array('<h3 class="staff-member-name">'.$name.'</h3>', '<h4 class="staff-member-position">'.$title.'</h4>', $photo, $email_mailto, $bio_format );
  126.    
  127.         $loop_markup = str_replace($accepted_single_tags, $replace_single_values, $loop_markup);
  128.         $loop_markup = str_replace($accepted_formatted_tags, $replace_formatted_values, $loop_markup);
  129.    
  130.         $output .= $loop_markup;
  131.    
  132.         $loop_markup = $loop_markup_reset;
  133.        
  134.        
  135.        
  136.         $output .= '</div> <!-- Close staff-member -->';
  137.         $i += 1;
  138.    
  139.        
  140.     endwhile;
  141.    
  142.     $output .= "</div> <!-- Close staff-member-listing -->";
  143.     }
  144.    
  145.     wp_reset_query();
  146.    
  147.     $output = $style_output.$output;
  148.    
  149.     $sslp_sc_output = do_shortcode($output);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement