function paginate_posts() {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$current = str_pad($current, 2, '0', STR_PAD_LEFT);
$total = str_pad($wp_query->max_num_pages, 2, '0', STR_PAD_LEFT);
$pagination_args = array(
'base' => @add_query_arg('page', '%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => false,
'end_size' => 0,
'mid_size' => 0,
'next_text' => _("»"),
'prev_text' => _("«"),
);
if ($wp_rewrite->using_permalinks())
$pagination_args['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');
if (!empty($wp_query->query_vars['s']))
$pagination_args['add_args'] = array('s' => get_query_var('s'));
$prev = get_previous_posts_link('');
$next = get_next_posts_link('');
$links = "<div class='pagination_box'><span class='prev page-num'>$prev</span> <span>Page $current/$total</span> <span class='next page-num'>$next</span></div>";
echo $links;
}
Pagination via above code works in taxonomy category pages. But when am calling this function in page <?php paginate_posts(); ?>
<?php paginate_posts(); ?>
it isn't working. But can't understand what is the issue ?
For making my pagination code work inside page I put code inside of page where I want to display pagination and then I added new query with my arguments and it works now. And my final code looks like this:
<?php
global $wp_query, $wp_rewrite;
$wp_query = new WP_Query($args);
$wp_query->query('post_type=product&paged='.get_query_var('paged').'&odrerby=ID&posts_per_page=15&order=DESC');
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$current = str_pad($current, 2, '0', STR_PAD_LEFT);
$total = str_pad($wp_query->max_num_pages, 2, '0', STR_PAD_LEFT);
$pagination_args = array(
'base' => @add_query_arg('page', '%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => false,
'end_size' => 0,
'mid_size' => 0,
'next_text' => _("»"),
'prev_text' => _("«"),
);
if ($wp_rewrite->using_permalinks())
$pagination_args['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');
if (!empty($wp_query->query_vars['s']))
$pagination_args['add_args'] = array('s' => get_query_var('s'));
$prev = get_previous_posts_link('');
$next = get_next_posts_link('');
$links = "<span class='pagexofy'><span class='prev page-numbers'>$prev</span> <span>PAGE $current/$total</span> <span class='next page-numbers'>$next</span></span>";
echo $links;
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.