File: /var/www/dev.captainschairit.com/wp-content/themes/captainschare/template-parts/blog.php
<?php
/**
* Template Name: Blogs Page
*/
get_header();
$banner_section = get_field('banner_section');
//echo '<pre>'; print_r($banner_section);
?>
<!-- Header -->
<header class="masthead-inner" style="background-image: url(<?php echo $banner_section['background_image'] ?>)">
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-8 offset-lg-2">
<div class="intro-text text-center blog-banner-text">
<div class="intro-heading"><?php echo $banner_section['text'] ?></div>
</div>
</div>
</div>
</div>
</header>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'ASC',
'post_type' => 'post',
'post_status' => 'publish',
'paged' => $paged,
);
$blog_posts = new WP_Query( $args );
// echo '<pre>'; print_r ($blog_posts); echo '</pre>';
?>
<!-- Services -->
<section class="page-section blog-section">
<div class="container">
<div class="row">
<div class="col-lg-10 offset-lg-1 text-center">
<!-- <h2 class="heading01 mb-5"><?php //echo get_the_title(); ?></h2> -->
</div>
<!-- WP-Post Start -->
<?php
if ( $blog_posts->have_posts() ) {
while ( $blog_posts->have_posts() ) : $blog_posts->the_post();
$postid = get_the_ID();
$featured_img_url = get_the_post_thumbnail_url($postid,'full');
$author_name = get_field( "author_name", $postid ); ?>
<div class="blog mt-5 mb-5">
<div class="col-sm-12">
<h3 class="heading03">
<small><?php echo get_the_date('F d, Y', $postid); ?></small>
<?php the_title(); ?>
</h3>
<p>By <span> <?php echo $author_name; ?></span></p>
<?php if($featured_img_url != '') { ?>
<figure>
<img src="<?php echo $featured_img_url; ?>" alt="<?php the_title(); ?>" class="img-fluid">
</figure>
<?php
} ?>
<p><?php
$content = get_the_content();
echo strip_tags(substr($content, 0, 270)).'...'; ?></p>
<a class="btn btn-primary text-uppercase mt-1 hvr-shutter-out-horizontal" href="<?php echo get_permalink($postid); ?>">Read More</a>
</div>
</div>
<?php
endwhile;
?>
<!-- Here Goes Pegination Start -->
<div class="pagination-section">
<ul class="pagination pull-right">
<?php
global $wp_query;
$big = 999999999;
$total_pages = $blog_posts->max_num_pages;
//echo $total_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
$links = paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'current' => $current_page,
'total' => $total_pages,
'type' => 'array',
'prev_text' => __('<i class="fa fa-angle-double-left" aria-hidden="true"></i>'),
'next_text' => __('<i class="fa fa-angle-double-right" aria-hidden="true"></i>')
));
foreach ($links as $link) { ?>
<li class="page-item"><?php echo str_replace('page-numbers', 'page-link', $link); ?></li>
<?php
}
}
?>
</ul>
</div>
<!-- Here Goes Pegination End -->
<?php
wp_reset_postdata();
} ?>
<!-- WP-Post End -->
</div>
</div>
</section>
<?php
get_footer();
?>