Back

Wordpress Blog Template with Pagination

Copy Below Code View As A Text File Show Text Only Show API Edit Code
                            

<?php /* Template Name: Blog Template */ get_header(); ?> <!--Page Title--> <section class="page-title"> <div class="container"> <div class="page-title-inner"> <h1><?php single_post_title(); ?></h1> <ul class="page-breadcrumb"> <li><a href="<?php echo get_site_url(); ?>">Home</a></li> <li><?php single_post_title(); ?></li> </ul> </div> </div> </section> <!--End Page Title--> <!-- News Start --> <section class="inner-page page_content"> <div class="container"> <div class="newspage"> <div class="row"> <?php /* $args = array( 'posts_per_page' => -1, 'post_type' => 'post', ); $the_query = new WP_Query( $args ); while ( $the_query->have_posts() ) { the_title(); the_content(); } */ ?> <?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( 'post_type' => 'post', 'posts_per_page' => 20, 'paged'=>$paged, ); $post_query = new WP_Query($args); if($post_query->have_posts() ) { while($post_query->have_posts() ) { $post_query->the_post(); ?> <div class="col-lg-4 col-md-6"> <div class="news-block"> <div class="inner-box"> <!--Image--> <div class="image"> <a href="<?php the_permalink() ?>"> <?php echo the_post_thumbnail( ); ?> </a> </div> <!--Lower Column--> <div class="lower-content"> <h3> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </h3> <div class="text"> <?php $content = get_the_content(); echo mb_strimwidth($content, 0, 200, '...');?> </div> <ul class="post-meta"> <li><i class="icon fas fa-calendar-alt"></i> <?php echo mysql2date( get_option( 'date_format' ), $post->post_date); ?></li> <li><a href="<?php the_permalink() ?>">Read More</a></li> </ul> </div> </div> </div> </div> <?php } } ?> </div> <!-- <div class="blog-pagination text-center"> <a href="<?php// previous_posts_link(); ?>"><i class="fas fa-angle-left"></i></a> <a href="#0">01</a> <a href="#0" class="active">02</a> <a href="#0">03</a> <a href="<?php //next_posts_link(); ?>"><i class="fas fa-angle-right"></i></a> </div> --> <!-- <a href=""><i class="fas fa-angle-left"></i></a> <a href="#0">01</a> <a href="#0" class="active">02</a> <a href="#0">03</a> <a href="#0"><i class="fas fa-angle-right"></i></a> </div> --> <div class="blog-pagination text-center"> <?php pagination_bar($post_query); ?> </div> </div> </section> <!-- News End --> <?php get_footer(); /********************************************/ // function for functions.php file function pagination_bar( $custom_query ) { $total_pages = $custom_query->max_num_pages; $big = 999999999; // need an unlikely integer if ($total_pages > 1){ $current_page = max(1, get_query_var('paged')); $html=paginate_links(array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => $current_page, 'total' => $total_pages, 'prev_text'=>'<i class="fas fa-angle-left"></i>', 'next_text'=>'<i class="fas fa-angle-right"></i>', )); $html=str_replace('current','active',$html); $html=str_replace('span','a',$html); echo $html; } }