<?php
/**
 * Shows 4 staff items @random
 * @package Ultra WordPress Theme
 * @since 1.0
 * @author AJ Clarke : http://wpexplorer.com
 * @copyright Copyright (c) 2012, AJ Clarke
 * @link http://wpexplorer.com
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */

if( of_get_option('staff_related','1') == '1' ) {
	
	//query posts
	$staff_posts = NULL;
	$staff_posts = new WP_Query(
		array(
			'post_type' => 'staff',
			'posts_per_page' => 4,
			'no_found_rows' => true,
			'orderby' => 'rand'
		)
	);
	
	//show galleries section if posts exist
	if( $staff_posts->posts ) : ?>
		
		<div id="related-staff" class="boxed clearfix">
			<h2 class="symple-heading lined text-align-left"><span><?php _e('Other Staff members', 'wpex'); ?></span></h2>
			<ul>
            	<?php
				// Loop through posts
				$wpex_staff_count=0;
				foreach ( $staff_posts->posts as $post ) : setup_postdata( $post );
					$wpex_staff_count++; ?>
                    <article class="staff-entry grid-4 <?php if ( $wpex_staff_count == '4' ) echo ' remove-margin'; ?>">
                        <?php
                        // Featured Image
                        if( has_post_thumbnail() ) { ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="staff-entry-img">
                                <img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ),  wpex_img( 'staff_entry_width' ), wpex_img( 'staff_entry_height' ), wpex_img( 'staff_entry_crop' ) ); ?>" alt="<?php echo the_title(); ?>" />
                            </a><!-- .staff-entry-img -->
                        <?php } ?>
                        <div class="staff-entry-details clearfix">
                            <header class="staff-entry-title">
								<h2>
                                    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                                    <?php
                                    // Staff position
                                    if(get_post_meta( get_the_ID(), 'wpex_staff_position', true) !=='') { ?>
                                        <div class="staff-entry-position"><span class="icon-double-angle-right"></span><?php echo get_post_meta( get_the_ID(), 'wpex_staff_position', true); ?></div>
                                    <?php } ?>
                                </h2>
                            </header>
                            <div class="staff-entry-excerpt">
                                <?php
                                // Excerpt
                                if(empty( $post->post_excerpt )) {
                                        echo wp_trim_words( strip_shortcodes( get_the_content() ), of_get_option( 'staff_entry_excerpt_trim', '20' ) ); ?>
                                        <a href="<?php the_permalink(); ?>" title="<?php _e('read more','wpex'); ?>" class="staff-entry-readmore"><?php _e('read more','wpex'); ?> &rarr;</a>	
                                <?php } else { the_excerpt(); } ?>
                            </div><!-- .staff-entry-content -->
                        </div><!-- .staff-entry-details -->
                    </article><!-- .staff-entry -->
                <?php endforeach; ?>
			</ul><!-- /galleries-content -->
		</div><!-- /home-galleries -->
		
	<?php
	endif;
	$staff_posts = $wpex_staff_count = NULL;
	wp_reset_postdata();
	
}