Created
September 19, 2016 14:35
-
-
Save codigoconjuan/d7de887fdf57bdf54d7419d3662c23d4 to your computer and use it in GitHub Desktop.
Paginación en WordPress con WP_Query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function custom_pagination($numpages = '', $pagerange = '', $paged='') { | |
| if (empty($pagerange)) { | |
| $pagerange = 2; | |
| } | |
| /** | |
| * This first part of our function is a fallback | |
| * for custom pagination inside a regular loop that | |
| * uses the global $paged and global $wp_query variables. | |
| * | |
| * It's good because we can now override default pagination | |
| * in our theme, and use this function in default quries | |
| * and custom queries. | |
| */ | |
| global $paged; | |
| if (empty($paged)) { | |
| $paged = 1; | |
| } | |
| if ($numpages == '') { | |
| global $wp_query; | |
| $numpages = $wp_query->max_num_pages; | |
| if(!$numpages) { | |
| $numpages = 1; | |
| } | |
| } | |
| /** | |
| * We construct the pagination arguments to enter into our paginate_links | |
| * function. | |
| */ | |
| $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>"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ul class="paginacion clear"> | |
| <li> | |
| <?php | |
| if (function_exists(custom_pagination)) { | |
| custom_pagination($custom_query->max_num_pages,"",$paged); | |
| } | |
| ?> | |
| </li> | |
| </ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment