WordPress Post Custom Pagination Without Plugin
This code helps you to create template and get post with pagination without using plugin.
<?php
/*
Template Name: Post Pagination without Plugin in WordPress
*/
get_header();
?>
<?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
) );
?>
<?php
function wp_pagination() {
global $wp_query;
$big = 12345678;
$page_format = 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,
'type' => 'array'
) );
if( is_array($page_format) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
echo '<div><ul>';
echo '<li><span>'. $paged . ' of ' . $wp_query->max_num_pages .'</span></li>';
foreach ( $page_format as $page ) {
echo "<li>$page</li>";
}
echo '</ul></div>';
}
}
?>
<article id="core_middle_column" class="col-md-8 col-sm-8"><div id="core_ajax_callback"></div>
<div class="clearfix" id="recentlistings">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array( 'posts_per_page' => 2, 'post_type' => 'post', 'post_status' => 'publish', 'post__in' => array(1, 2, 3, 4), 'paged' => $paged ));
if ( have_posts() ) : ?>
<div class="_searchresultsdata">
<div class="panel panel-default">
<div class="list_style wlt_search_results row">
<?php while ( have_posts() ) : the_post(); ?>
<div class="itemdata col-md-4 item-121 col-sm-6 col-xs-12">
<div class="thumbnail clearfix">
<?php echo get_the_title();?>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
<div class="custom_pagination"><?php wp_pagination(); ?></div>
<?php else : ?>
<?php // no posts found message goes here ?>
<?php endif; ?>
</div>
</article>
<style>
.custom_pagination ul {
display: initial;
}
.custom_pagination li:first-child{
background-color: #fff;
border: 1px solid #ddd;
color: #0b5b96;
list-style: outside none none !important;
padding: 6px 12px !important;
text-decoration: none;
border-radius:15px;
float:right !important;
}
.custom_pagination li {
float: left !important;
list-style: outside none none !important;
}
.custom_pagination .page-numbers {
background-color: #fff;
border: 1px solid #ddd;
color: #0b5b96;
list-style: outside none none !important;
padding: 6px 12px !important;
text-decoration: none;
float: left;
}
.page-numbers.current {
background-color: #0b5b96 !important;
color: #fff !important;
}
</style>
<?php
get_footer();
?>
No comments:
Post a Comment