<?php
/**
 * Shows 4 portfolio 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('portfolio_related','1') == '1' ) {
	
	//query posts
	$portfolio_posts = NULL;
	$portfolio_posts = new WP_Query(
		array(
			'post_type' 		=> 'portfolio',
			'posts_per_page'	=> 4,
			'no_found_rows'		=> true,
			'orderby' 			=> 'rand'
		)
	);
	
	//show galleries section if posts exist
	if( $portfolio_posts->posts ) : ?>
		
		<div id="related-portfolio" class="boxed clearfix">
			<h2 class="symple-heading lined text-align-left"><span><?php _e('Other Items', 'wpex'); ?></span></h2>
			<?php
			$count=0;
            // Loop through posts
            foreach ( $portfolio_posts->posts as $post ) : setup_postdata( $post );
				$count++; ?>
                <article class="portfolio-entry grid-4 <?php if ( $count == '4' ) echo 'remove-margin'; ?>">
					<?php
                    // Display post thumbnail
                    if( has_post_thumbnail() ) { ?>
                        <div class="portfolio-entry-media">
                            <a href="<?php echo wpex_portfolio_url( get_the_ID(), $lightbox_only = false ); ?>" title="<?php the_title(); ?>" class="portfolio-entry-img <?php if( get_post_meta(get_the_ID(), 'wpex_portfolio_post_style', true) == 'Lightbox' ) echo 'fancybox-media'; ?>">
                                <img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), wpex_img( 'port_entry_width' ), wpex_img( 'port_entry_height' ), wpex_img( 'port_entry_crop' ) ); ?>" alt="<?php the_title(); ?>" />
                                <div class="portfolio-entry-overlay">
                                    <div class="portfolio-entry-overlay-inner">
                                        <div class="overlay-icon"><span class="icon-<?php echo wpex_portfolio_icon( get_the_ID(), false ); ?>"></span></div>
                                    </div><!-- .portfolio-entry-overlay-inner -->
                                </div><!-- .portfolio-entry-overlay -->
                            </a><!-- .portfolio-entry-img -->      
                        </div><!-- .portfolio-entry-media -->
					<?php } //end has_post_thumbnail() check ?>
                    <div class="portfolio-entry-details">
                        <div class="portfolio-entry-title">
                            <h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
                        </div><!-- .portfolio-entry-title -->
                        <div class="portfolio-entry-excerpt">
                            <?php
                            // Display trimmed content if excerpt is blank
                            echo ( !empty( $post->post_excerpt ) ) ? apply_filters('the_content', get_the_excerpt()) : wp_trim_words( strip_shortcodes( get_the_content() ), 18); ?>
                            <?php
                            // Display read more link if enabled
                            if (of_get_option('portfolio_entry_readmore','0') == '1' ) { ?>
                            <br />
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="portfolio-entry-readmore"><?php _e('read more','wpex'); ?> &rarr;</a>
                            <?php } ?>
                        </div><!-- .portfolio-entry-excerpt -->
                    </div><!-- .portfolio-entry-details -->
				</article><!-- .portfolio-entry -->
            <?php endforeach; // End foreach wp_query->posts as $post ?>
		</div><!-- /home-galleries -->
		
	<?php
	$portfolio_posts = $count = NULL; // clear vars
	endif; // End $wp_query->posts check
	wp_reset_postdata(); // Reset postdata
}