<?php
/*
Template Name: blog
 */

get_header(); ?>

<!-- main banner-->
<div class="container-fluid">
    <div class="row">
         <?php while (have_posts()) : the_post(); ?>
             <div class="mainBanner">
                <?php the_post_thumbnail('full', ['class' => 'img-responsive']);  ?> 
            </div>
            <div class="mainMobileBanner">
             <?php
            MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image', NULL, 'post-secondary-image-thumbnail');
                ?> 
            </div>
        <?php endwhile;
            wp_reset_query(); //resetting the page query
         ?>        
    </div> <!-- row----->
</div><!--container-fluid--->

<!----Bread crumbs ---->
<div class="container-fluid myhcrumbs">
    <div class="container">
        <div class="crumbs"><?php echo do_shortcode('[simple_crumbs root="Home" /]') ?>	» <a href="<?php echo site_url(); ?>"><?php echo the_title(); ?></a></div>
    </div>
</div>
<!-- bread crumbs end -->

<!-- page title -->
<div class="container-fluid">
    <div class="container ">
        <h2 class="PageTitle">Our <span>Blog</span></h2>
        <div class="implantImage"><img src="<?php echo site_url();?>/../wp-content/themes/dentalcourses/images/Line-border-2.png"/></div>
    </div><!-- container----->
</div><!--container-fluid--->



<div class="container-fluid blog">
	<div class="container">
		<div class="row">
			<div class="col-md-8 col-sm-12 col-xs-12">
				<div class="my-blog-page">
				
						<ul class="list-of-blogs">
							<?php
					if ( get_query_var('paged') ) {
						$paged = get_query_var('paged');
					} elseif ( get_query_var('page') ) { // 'page' is used instead of 'paged' on Static Front Page
						$paged = get_query_var('page');
					} else {
						$paged = 1;
					}

					$custom_query_args = array(
						'post_type' => 'post', 
						'posts_per_page' => get_option('posts_per_page'),
						'paged' => $paged,
						'post_status' => 'publish',
						'ignore_sticky_posts' => true,
						//'category_name' => 'custom-cat',
						'order' => 'DESC', // 'ASC'
						'orderby' => 'date' // modified | title | name | ID | rand
					);
					$custom_query = new WP_Query( $custom_query_args );

					if ( $custom_query->have_posts() ) :
						while( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
								<li class="col-md-12 col-sm-12 col-xs-12">
									<div class="row">
										<div class="first-blog">
											<a href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
											<h2><a href="<?php echo get_permalink(); ?>"><?php echo the_title(); ?></a></h2>
											<h3 class="col-md-6 col-sm-6 col-xs-12">
												<i class="fa fa-calendar-o" aria-hidden="true"></i>
												<?php echo get_the_date();?>
											</h3>
											<h3 class="col-md-6 col-sm-6 col-xs-12" style="text-align:right;">
												<i class="fa fa-comments" aria-hidden="true"></i>
												<?php comments_number(); ?>
											</h3>
											<div class="singlecontent"><?php echo the_excerpt(); ?></div>
											
											<div class="read-more">
												<div class="on-center">
													<a href="<?php echo get_permalink(); ?>" class="btn"><span class="btn_text">Read more</span></a>
												</div>
											</div>
										</div>
									</div>
								</li>
							<?php endwhile; ?>

						<?php if ($custom_query->max_num_pages > 1) : // custom pagination  ?>
							<?php
							$orig_query = $wp_query; // fix for pagination to work
							$wp_query = $custom_query;
							?>
							<div class="for-pagination">
								<div class="navigation">
									<?php
										global $wp_query;

										$big = 999999999; // need an unlikely integer

										echo paginate_links( array(
											'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
											'format' => '?paged=%#%',
											'current' => max( 1, get_query_var('paged') ),
											'total' => $wp_query->max_num_pages
										) );
									?>
								</div><!-- /.navigation -->
							</div>
							<?php
							$wp_query = $orig_query; // fix for pagination to work
							?>
						<?php endif; ?>

						<?php
							wp_reset_postdata(); // reset the query 
						else:
							echo '<p>'.__('Sorry, no posts matched your criteria.').'</p>';
						endif;
						?>
						</ul>
						
				</div>
			</div>
			<div class="col-md-4 col-sm-12 col-xs-12">
			
				<div class="blog-sidebar">
					<div id="secondary">
					
						<?php get_sidebar(); ?>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
	
<?php get_footer(); ?>