Created
October 3, 2013 17:58
-
-
Save jazzsequence/6814140 to your computer and use it in GitHub Desktop.
Bootstrapping wp_link_pages - a wp_link_pages alternative for Twitter Bootstrap support. Based on code found here: http://wordpress.stackexchange.com/questions/14406/how-to-style-current-page-number-wp-link-pages
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
<?php | |
/** | |
* Link Pages | |
* @author toscha | |
* @link http://wordpress.stackexchange.com/questions/14406/how-to-style-current-page-number-wp-link-pages | |
* @param array $args | |
* @return void | |
* Modification of wp_link_pages() with an extra element to highlight the current page. | |
*/ | |
function bootstrap_link_pages( $args = array () ) { | |
$defaults = array( | |
'before' => '<p>' . __('Pages:'), | |
'after' => '</p>', | |
'before_link' => '', | |
'after_link' => '', | |
'current_before' => '', | |
'current_after' => '', | |
'link_before' => '', | |
'link_after' => '', | |
'pagelink' => '%', | |
'echo' => 1 | |
); | |
$r = wp_parse_args( $args, $defaults ); | |
$r = apply_filters( 'wp_link_pages_args', $r ); | |
extract( $r, EXTR_SKIP ); | |
global $page, $numpages, $multipage, $more, $pagenow; | |
if ( ! $multipage ) | |
{ | |
return; | |
} | |
$output = $before; | |
for ( $i = 1; $i < ( $numpages + 1 ); $i++ ) | |
{ | |
$j = str_replace( '%', $i, $pagelink ); | |
$output .= ' '; | |
if ( $i != $page || ( ! $more && 1 == $page ) ) | |
{ | |
$output .= "{$before_link}" . _wp_link_page( $i ) . "{$link_before}{$j}{$link_after}</a>{$after_link}"; | |
} | |
else | |
{ | |
$output .= "{$current_before}{$link_before}<a>{$j}</a>{$link_after}{$current_after}"; | |
} | |
} | |
print $output . $after; | |
} | |
?> |
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
<?php | |
$args = array( | |
'before' => '<ul class="pagination">', | |
'after' => '</ul>', | |
'before_link' => '<li>', | |
'after_link' => '</li>', | |
'current_before' => '<li class="active">', | |
'current_after' => '</li>', | |
'previouspagelink' => '«', | |
'nextpagelink' => '»' | |
); | |
bootstrap_link_pages( $args ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment