Created
September 9, 2013 14:55
-
-
Save xposedbones/6496731 to your computer and use it in GitHub Desktop.
Wordpress Pagination
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 hwl_home_pagesize( $query ) { | |
global $allposts,$latestpost; | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
if(CONDITION){ | |
$query->query_vars['posts_per_page']=1; | |
$query->query_vars['paged'] = $paged; | |
return; | |
} | |
return; | |
} | |
add_action('pre_get_posts', 'hwl_home_pagesize', 1); | |
function theme_paginate($nav_id, $query = null, $issearch){ | |
global $wp_query, $post, $translation_name; | |
$url = explode("/",$_SERVER['REQUEST_URI']); | |
array_shift($url); | |
array_pop($url); | |
$big = 999999999; // need an unlikely integer | |
if($query==NULL){ | |
$query = $wp_query; | |
} | |
$url = implode("/",$url); | |
if ( $query->max_num_pages > 1 ) : | |
$pagination = array( | |
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), | |
'format' => '?paged=%#%', | |
'current' => max( 1, get_query_var('paged') ), | |
'total' => $wp_query->max_num_pages, | |
'show_all' => false, | |
'prev_next'=>true, | |
'prev_text'=>"<span class=\"icon-caret-left\"></span>".sprintf('<span class="hidden">%s</span>',__("Previous",$translation_name)), | |
'next_text'=>sprintf('<span class="hidden">%s</span>',__("Next",$translation_name))."<span class=\"icon-caret-right\"></span>", | |
'type' => 'plain', | |
); | |
?> | |
<nav id="<?php echo $nav_id; ?>" class="navigation-pages group wrap980"> | |
<?php if ($issearch): ?> | |
<div class="search-results"><?php printf( | |
_n( '%1$s result', '%1$s results', $query->found_posts, $translation_name ), | |
number_format_i18n($query->found_posts) | |
); ?></div> | |
<?php endif ?> | |
<div class="pagination"><?php echo paginate_links( $pagination ); ?></div> | |
</nav> | |
<?php endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment