Pager for Older & Newer Posts/Comments
Changes to the Bootstrap CSS means that the .pager class only applies to <li> and not <div> used by the current Roots setup. The change was made on purpose by the Bootstrap devs, which is why I'm posting here.
The current code will also produce empty tags when there are no previous/next posts, so it could do with a bit of a cleanup. Perhaps by adding .disabled class when the Wordpress function returns null.
Both the post-nav and comments-nav are affected. I think the page paging is different, but feel free to correct me if I'm wrong.
The changes should be easy to implement and I can issue a pull tomorrow if that's helpful.
pull req would be awesome, thanks for creating this issue
you're right about the page paging being different. using disabled sounds like a good idea
I was wrong about it being easy. Unlike a lot of Wordpress functions you cannot change the container with the function or a filter.
My solution would be a new function in /lib/nav.php:
/**
* Generate previous/next pager items wrapped in <li> and add .disabled placeholder when empty.
* Set $placeholder to anything other than 'show' to remove.
*/
function roots_pager_link($direction, $type, $placeholder = 'show') {
$checkVars = ($direction != 'older' && $direction != 'newer' ? false : ($type != 'comments' && $type != 'posts' ? false : true));
if (!$checkVars) {
return;
}
else {
$label = ($direction == 'older' ? __('← Older '. $type .'', 'roots' ) : __('Newer '. $type .' →', 'roots'));
$class = ($direction == 'older' ? 'previous' : 'next');
if ($type == 'posts') {
$link = ($direction == 'older' ? get_next_posts_link($label) : get_previous_posts_link($label));
}
elseif ($type == 'comments') {
$link = ($direction == 'older' ? get_previous_comments_link($label) : get_next_comments_link($label));
}
$label = ($placeholder == 'show' ? '<li class="'. $class .' disabled"><a>'. $label .'</a></li>' : '');
$output = (!empty($link) ? '<li class="'. $class .'">'. $link .'</li>' : $label );
echo $output ."\n";
}
}
So it would be called like so;
<nav id="post-nav">
<ul class="pager">
<?php roots_pager_link('older', 'posts'); ?>
<?php roots_pager_link('newer','posts'); ?>
</ul>
</nav>
I didn't know the protocol for changes like this, so I thought I'd best check here first.
EDIT: I thought the new function was overkill and just added more if/else statements.