<?php
/**
 * Template Name: Blog
 * Outputs a list of your latest regular posts
 * @package S-Corp 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
 */

get_header(); // Loads the header.php template
if (have_posts()) : while (have_posts()) : the_post(); // Start loop
get_template_part( 'content-page', 'slider' ); // Get slider

// vars
$wpex_page_featured_img_overlay = get_post_meta( get_the_ID(), 'wpex_page_featured_img_overlay', true );

// Show featured image
if( has_post_thumbnail( get_the_ID() ) ) { ?>
	<div id="page-featured-img" <?php if ( $wpex_page_featured_img_overlay !== '' ) echo 'class="with-overlay"'; ?>>
		<img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ),  wpex_img( 'page_width' ), wpex_img( 'page_height' ), wpex_img( 'page_crop' ) ); ?>" alt="<?php echo the_title(); ?>" />
        <?php
		// show overlay over featured image as defined via the custom field
        if ( $wpex_page_featured_img_overlay !== '' ) {
			echo '<div id="page-featured-img-overlay">'. do_shortcode( wpautop( htmlspecialchars_decode( $wpex_page_featured_img_overlay ) ) ) .'
					</div><!-- #page-featured-img-overlay -->';
		} ?>
    </div><!-- #page-featured-img -->
<?php }

// Show header unless disabled via the custom field "wpex_page_disable_heading"
if ( get_post_meta( get_the_ID(), 'wpex_page_disable_heading', true) !== 'yes' ) { ?>
    <header id="page-heading">
        <div class="boxed">
            <h1><?php the_title(); ?></h1>
            <?php
            // Yoast Breadcrumbs Support
            if( function_exists('yoast_breadcrumb') ) yoast_breadcrumb('<div id="breadcrumbs"><span class="icon-home"></span>','</div>'); ?>
        </div><!-- /boxed -->
    </header><!-- /page-heading -->
<?php } ?>

<div id="blog-template-content" class="boxed container clearfix">
	<?php
    // Add #post div on all blog styles except full-width
	if ( of_get_option('blog_entry_style','large_image') !== 'full_image') {
		echo '<div id="post" class="clearfix">';
	}
        // Query regular posts
		query_posts( array(
			'post_type' => 'post',
			'paged' => $paged
		) );
        if( have_posts() ) :
            while ( have_posts()) : the_post();
                get_template_part( 'content', get_post_format() );
            endwhile;      	
			wpex_pagination(); // Paginate your posts
		endif;
		wp_reset_query(); // Reset the query to avoid any conflicts later on
		
    // Close #post div on all blog styles except full-width & get sidebar
	if ( of_get_option('blog_entry_style','large_image') !== 'full_image') {
		echo '</div>';
		// Load sidebar if post isn't full-width
		if( get_post_meta( get_the_ID(), 'wpex_post_layout', true ) !== 'Full Width' ) {
			get_sidebar();
		}
	} ?>
</div><!-- #blog-template-content -->

<?php
$wpex_page_featured_img_overlay = NULL;
endwhile; endif;
get_footer(); // Loads the footer.php file ?>