'Change default pagination style in wordpress
I am beginner in WordPress and started to learn it. I am designing a new child theme from an existing parent theme. The Pagination of Home page in parent
« Previous 1 2 3 Next »
But I want to modify it like this:
Page 1 of 45 1 2 3 NEXT 10 20 30 LAST
Following is my code :
if (!is_singular()) {
global $wp_query, $rtp_post_comments;
if (isset($rtp_post_comments['pagination_show']) && $rtp_post_comments['pagination_show']) {
if (( $wp_query->max_num_pages > 1)) {
?>
<nav class="wp-pagenavi"><?php
echo "<span class='page-count'>Page 1 of " . $wp_query->max_num_pages . "</span>";
echo paginate_links(array(
'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'prev_text' => esc_attr($rtp_post_comments['prev_text']),
'next_text' => esc_attr($rtp_post_comments['next_text']),
'end_size' => $rtp_post_comments['end_size'],
'mid_size' => $rtp_post_comments['mid_size']
));
?>
</nav><?php
}
} elseif (function_exists('wp_pagenavi')) {
wp_pagenavi();
} elseif (get_next_posts_link() || get_previous_posts_link()) {
?>
<nav class="navigation clearfix">
<?php if (get_next_posts_link()) { ?><div class="alignleft"><?php next_posts_link(__('Older Entries')); ?></div><?php } ?>
<?php if (get_previous_posts_link()) { ?><div class="alignright"><?php previous_posts_link(__('Newer Entries')); ?></div><?php } ?>
</nav><?php
}
}
Where should I change this?
Solution 1:[1]
Have a look at paginate links codex page
paginate_links() is located in wp-includes/general-template.php. (It is not advised to edit the core files.)
Or you can try this plugin: WP-PageNavi which will give an option to add "Page 1 of 45" on the beginning.
Solution 2:[2]
I've found that for some of the custom stuff wordpress functions are less than understandable. But a nice workaround is this:
global $page, $numpages;
if ( $numpages > 1 ) :
if ( $page == 1 ) {
$prev_link = ' ';
$next_link = '<a href="' . get_permalink() . ( $page+1 ) . '">Next Page</a>';
} else if ( $page == $numpages ) {
$prev_link = '<a href="' . get_permalink() . ( $page-1 ) . '">Prev. Page</a>';
$next_link = ' ';
} else {
$prev_link = '<a href="' . get_permalink() . ( $page-1 ) . '">Prev. Page</a>';
$next_link = '<a href="' . get_permalink() . ( $page+1 ) . '">Next Page</a>';
}
?>
<div id="post-pagination">
<div class="prev-page"><?php echo $prev_link; ?></div>
<div class="spacer"><?php echo $page.' / '.$numpages; ?></div>
<div class="next-page"><?php echo $next_link ?></div>
</div>
This is very easy to customize, style AND understand.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Libin |
| Solution 2 | Federico Jacobi |
