My pagination is not working on front page for custom post type, its working properly when is not select for front page.
My code in functions.php
/** pagination **/
function fruit_pagination($pages = '', $range = 5)
{
$fruit_showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
} echo '
<div class="site-pagination">';
if(1 != $pages)
{
echo "
<ul>
";
if($paged > 2 && $paged > $range+1 && $fruit_showitems < $pages) echo "
<li class='pagination-previous-all'>
<a href='".get_pagenum_link(1)."'>
<span class='sprite previous-all-icon'>First</span></a></li>
";
if($paged > 1 && $fruit_showitems < $pages) echo "
<li class='pagination-previous'>
<a href='".get_pagenum_link($paged - 1)."'>
<span class='sprite previous-icon'>Previous</span></a></li>
";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 ||
$i <= $paged-$range-1) || $pages <= $fruit_showitems ))
{
echo ($paged == $i)? "
<li class='active'><a href='#' >".$i."</a></li>
":"
<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>
";
}
}
if ($paged < $pages && $fruit_showitems < $pages) echo "
<li class='pagination-next'>
<a href='".get_pagenum_link($paged + 1)."'>
<span class='sprite next-icon'>Next</span></a></li>
";
if ($paged < $pages-1 && $paged+$range-1 < $pages &&
$fruit_showitems < $pages) echo "
<li class='pagination-next-all'>
<a href='".get_pagenum_link($pages)."'>
<span class='sprite next-all-icon'>Last</span></a></li>
";
echo "
</ul>
\n";
}
echo '</div>
';
}
/** End pagination **/
My code in Custom Page Template and it is selected for Front Page
global $paged;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$rarthemes_html_args = array(
'paged' => $paged,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'html',
'post_status' => 'publish',
);
$rarthemes_html = new WP_Query($rarthemes_html_args);
while ($rarthemes_html->have_posts())
{ $rarthemes_html->the_post(); the_title(); }
<div class="col-md-12">
<?php
if (function_exists('fruit_pagination')) {
fruit_pagination($rarthemes_html->max_num_pages, '2');
}
?>
</div>
get_query_var( 'page' )
and notget_query_var( 'paged' )
. Please consider using the site search as there are tons on info on this same exact issue – Pieter Goosen Jan 12 '16 at 5:24get_query_var( 'page' )
is not working anymore, it just returns empty string. – Matija Mrkaic Jan 12 '16 at 10:34get_query_var('page')
. Can be tracked here: core.trac.wordpress.org/ticket/35344 – Matija Mrkaic Jan 12 '16 at 10:51