<?php
/**
 * This template displays the blog loop.
 *
 * @package Organic Startup
 * @since Organic Startup 1.0
 */

?>

<?php $blog_query['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; ?>

<?php $blog_cats = get_theme_mod( 'organic_startup_blog_category', '0' ); ?>
<?php if ( is_array( $blog_cats ) && ! empty( $blog_cats ) ) { $categories = implode( ',', $blog_cats ); } ?>

<?php
	$blog_query = new WP_Query( array(
		'cat'              => $categories,
		'paged'            => $paged,
		'suppress_filters' => 0,
	) );
?>

<?php if ( $blog_query->have_posts() ) : while ( $blog_query->have_posts() ) : $blog_query->the_post(); ?>

	<!-- BEGIN .post class -->
	<div <?php post_class( 'blog-holder' ); ?> id="post-<?php the_ID(); ?>">

		<?php if ( has_post_thumbnail() && wp_is_mobile() ) { ?>
			<a class="feature-img" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo esc_attr( sprintf( esc_html__( 'Permalink to %s', 'organic-startup' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_post_thumbnail( 'startup-featured-medium' ); ?></a>
		<?php } elseif ( has_post_thumbnail() ) { ?>
			<a class="feature-img" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo esc_attr( sprintf( esc_html__( 'Permalink to %s', 'organic-startup' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_post_thumbnail( 'startup-featured-large' ); ?></a>
		<?php } ?>

		<!-- BEGIN .article -->
		<article class="article clearfix">

			<h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php esc_attr( the_title_attribute() ); ?>"><?php the_title(); ?></a></h2>

			<?php if ( ! empty( $post->post_excerpt ) ) { ?>

				<div class="excerpt"><?php the_excerpt(); ?></div>

			<?php } ?>

			<!-- BEGIN .entry-content -->
			<div class="entry-content">

				<?php
				the_content( sprintf(
					__( 'Continue Reading<span class="screen-reader-text"> "%s"</span>', 'organic-startup' ),
					get_the_title()
				) );
				?>

			<!-- END .entry-content -->
			</div>

		<!-- END .article -->
		</article>

	<!-- END .post class -->
	</div>

<?php endwhile; ?>

	<?php if ( $blog_query->max_num_pages > 1 ) { ?>

		<?php the_posts_pagination( array(
			'prev_text' => '<span class="meta-nav screen-reader-text">' . esc_html__( 'Previous Page', 'organic-startup' ) . ' </span>&laquo;',
			'next_text' => '<span class="meta-nav screen-reader-text">' . esc_html__( 'Next Page', 'organic-startup' ) . ' </span>&raquo;',
		) ); ?>

	<?php } ?>

<?php else : ?>

	<!-- BEGIN .page-holder -->
	<div class="page-holder">

		<!-- BEGIN .article -->
		<article class="article">

			<?php get_template_part( 'content/content', 'none' ); ?>

		<!-- END .article -->
		</article>

	<!-- END .page-holder -->
	</div>

<?php endif; ?>
<?php wp_reset_query(); ?>
