I have a custom page, where I show the posts from the articles section.
I want to show 6 posts per page, and use a numbered pagination.
Everytime I have to use 'pagination' outside archive.php or something like that, I have problems.
Any ideas on how can I resolve that?
My code:
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $paged,
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) :
while($post_query->have_posts() ) :
$post_query->the_post();
the_title();
endwhile;
if (function_exists(custom_pagination)) {
custom_pagination($custom_query->max_num_pages,"",$paged);
}
endif;
wp_reset_postdata();
?>
My 'functions.php':
(I followed this tutorial: http://callmenick.com/post/custom-wordpress-loop-with-pagination)
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='custom-pagination'>";
echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
}