I'm trying to use Wordpress paginate function to only show 3 pages at most(client wants it this way) so that when you go up a page it shows the current page you're on and the previous and next page:
Unfortunately when I do it I get several pages including the last page:
This is my current paginate code, please note the format is like this because I have Tabs that each need to be paged with different queries
echo '<div id ="nav_pages">';
echo '<div class="prev_first"></div>';
echo '<div class="pages">';
$pag_args1 = array(
'type' => 'list',
'prev_next' => False,
'end_size' => 1,
'add_args' => false,
'add_fragment' => '',
'show_all' => false,
'base' => '' . $url . '?paged1=%#%',
'format' => '?paged1=%#%',
'current' => $paged1,
'total' => $get_mining->max_num_pages);
echo paginate_links( $pag_args1 );
echo '</div>';
echo '<div class="page_x_of_y2">Page <span>' . $paged1 . '</span> of <span>' . $get_mining->max_num_pages . '</span></div>';
echo '</div>';
Is there anyway I can modify this code to look like the pagination in the first image rather than what it looks like in the second one? Do I need to write a custom paginate function to achieve this? I dont agree with what the client wants as I feel like the latter is a better option but you know what they say: "The customer is always right"
UPDATED PARTIAL SOLUTION
So after doing bit more reseach I found this link:Getting paginate_links()'end_size' to display 0 This solution almost allows me to achieve the goal I want here is my modified code:
echo '<div id ="nav_pages">';
echo '<div class="prev_first"></div>';
echo '<div class="pages">';
$pag_args1 = array(
'type' => 'array',
'prev_next' => False,
'end_size' => 0,
'mid_size' => 1,
'add_args' => false,
'add_fragment' => '',
'show_all' => false,
'base' => '' . $url . '?paged1=%#%',
'format' => '?paged1=%#%',
'current' => $paged1,
'total' => $get_mining->max_num_pages);
$paginate_links = paginate_links( $pag_args1 );
$c=$pag_args1['current'];
$allowed=[sprintf('/?paged1=%d',$c-1),'current',sprintf('?paged1=%d',$c+1)];
$paginate_links=array_filter(
$paginate_links,
function( $value ) use ( $allowed ) {
foreach( (array) $allowed as $tag )
{
if( false !== strpos( $value, $tag ) )
return true;
}
return false;
}
);
if( ! empty( $paginate_links ) )
printf("<ul class='page-numbers'>\n\t<li>%s</li>\n</ul>\n",join( "</li>\n\t<li>", $paginate_links));
echo '</div>';
echo '<div class="page_x_of_y2">Page <span>' . $paged1 . '</span> of <span>' . $get_mining->max_num_pages . '</span></div>';
echo '</div>';
}//Endif
This almost achieves what I want, the only problem now is that it wont show the previous page when I go above page 1. I'm getting Closer!!