Last active
April 6, 2016 14:47
-
-
Save mayukojpn/e3b0940cd57dec2ac268cfe5247ff9b8 to your computer and use it in GitHub Desktop.
This file contains 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
Index: custom-nextpage.php | |
=================================================================== | |
--- custom-nextpage.php (revision 1388038) | |
+++ custom-nextpage.php (working copy) | |
@@ -142,7 +142,7 @@ | |
} | |
public function wp_link_pages( $output = '' ) { | |
- global $page, $numpages, $multipage, $pagenow; | |
+ global $wp_query, $wp_rewrite, $page, $numpages, $multipage, $pagenow; | |
$output = ''; | |
if ( $multipage ) { | |
$show_all = (boolean) $this->show_all; | |
@@ -171,18 +171,25 @@ | |
$output .= '<li class="previous">' . $link . $previouspagelink . '</a></li>'; | |
} | |
- $p_base = get_permalink(); | |
- $p_format = '%#%'; | |
+ // Setting up default values based on the current URL. | |
+ $pagenum_link = html_entity_decode( get_pagenum_link() ); | |
+ $url_parts = explode( '?', $pagenum_link ); | |
- if($word = strpos($p_base, '?')){ | |
- $p_base = get_option(home).(substr(get_option(home), -1 ,1) === '/' ? '' : '/') | |
- .'%_%'.substr($p_base, $word); | |
- } else{ | |
- $p_base .= (substr($p_base, -1 ,1) === '/' ? '' : '/') .'%_%'; | |
- } | |
+ // Get max pages and current page out of the current query, if available. | |
+ $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; | |
+ $current = get_query_var( 'page' ) ? intval( get_query_var( 'page' ) ) : 1; | |
+ | |
+ // Append the format placeholder to the base URL. | |
+ $pagenum_link = trailingslashit( $url_parts[0] ) . '%_%'; | |
+ | |
+ // URL base depends on permalink settings. | |
+ $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; | |
+ $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'page' ) : '?page=%#%'; | |
+ | |
+ | |
$nav_list = paginate_links(array( | |
- 'base' => $p_base, | |
- 'format' => $p_format, | |
+ 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below) | |
+ 'format' => $format, // ?page=%#% : %#% is replaced by the page number | |
'total' => $numpages, | |
'current' => ($page ? $page : 1), | |
'show_all' => $show_all, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment