Last active
May 25, 2017 20:10
-
-
Save joelstransky/94611f105137b7769ac63482492904ae to your computer and use it in GitHub Desktop.
Wraps WordPress paginate_links data in Twitter bootstrap pagination component
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
<?php | |
if ( ! function_exists('paginate_links_as_bootstrap') ) : | |
/** | |
* paginate_links_as_bootstrap() | |
* JPS 20170330 | |
* Wraps paginate_links data in Twitter bootstrap pagination component | |
* @param array $args { | |
* Optional. {@see 'paginate_links'} for native argument list. | |
* | |
* @type string $nav_class classes for <nav> element. Default empty. | |
* @type string $ul_class additional classes for <ul.pagination> element. Default empty. | |
* @type string $li_class additional classes for <li> elements. | |
* } | |
* @return array|string|void String of page links or array of page links. | |
*/ | |
function paginate_links_as_bootstrap ( $args = '' ) { | |
$args['type'] = 'array'; | |
$defaults = array( | |
'nav_class' => '', | |
'ul_class' => '', | |
'li_class' => '' | |
); | |
$args = wp_parse_args( $args, $defaults ); | |
$page_links = paginate_links( $args ); | |
if ( $page_links ) { | |
$r = ''; | |
$nav_class = empty($args['nav_class']) ? '' : 'class="' . $args['nav_class'] . '"'; | |
$ul_class = empty($args['ul_class']) ? '' : ' ' . $args['ul_class']; | |
$r .= '<nav '. $nav_class .' aria-label="navigation">' . "\n\t"; | |
$r .= '<ul class="pagination'. $ul_class .'">' . "\n"; | |
foreach ($page_links as $link) { | |
$li_classes = explode(" ", $args['li_class']); | |
strpos($link, 'current') !== false ? array_push($li_classes, 'active') : ( strpos($link, 'dots') !== false ? array_push($li_classes, 'disabled') : '' ); | |
$class = empty($li_classes) ? '' : 'class="' . join(" ", $li_classes) . '"'; | |
$r .= "\t\t" . '<li ' . $class . '>' . $link . '</li>' . "\n"; | |
} | |
$r .= "\t</ul>"; | |
$r .= "\n</nav>"; | |
return $r; | |
} | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment