Skip to content

Commit bb68b74

Browse files
committed
Update pagination with a simpler setup
I noticed WooCommerce's pagination system was nice and simple, and it also corresponds to what's on the Codex for paginate_links(): http://codex.wordpress.org/Function_Reference/paginate_links I did not include the rendered CSS (library/style.css), because whatever version of Sass CodeKit is using wanted to change every line, putting braces on the same line as the last declaration, etc. Signed-off-by: Gabriel Luethje <gabriel@thefstopdesign.com>
1 parent d1b3b54 commit bb68b74

2 files changed

Lines changed: 56 additions & 141 deletions

File tree

library/bones.php

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -309,59 +309,27 @@ function bones_related_posts() {
309309
*********************/
310310

311311
// Numeric Page Navi (built into the theme by default)
312-
function bones_page_navi($before = '', $after = '') {
313-
global $wpdb, $wp_query;
314-
$request = $wp_query->request;
315-
$posts_per_page = intval(get_query_var('posts_per_page'));
316-
$paged = intval(get_query_var('paged'));
317-
$numposts = $wp_query->found_posts;
318-
$max_page = $wp_query->max_num_pages;
319-
if ( $numposts <= $posts_per_page ) { return; }
320-
if(empty($paged) || $paged == 0) {
321-
$paged = 1;
322-
}
323-
$pages_to_show = 7;
324-
$pages_to_show_minus_1 = $pages_to_show-1;
325-
$half_page_start = floor($pages_to_show_minus_1/2);
326-
$half_page_end = ceil($pages_to_show_minus_1/2);
327-
$start_page = $paged - $half_page_start;
328-
if($start_page <= 0) {
329-
$start_page = 1;
330-
}
331-
$end_page = $paged + $half_page_end;
332-
if(($end_page - $start_page) != $pages_to_show_minus_1) {
333-
$end_page = $start_page + $pages_to_show_minus_1;
334-
}
335-
if($end_page > $max_page) {
336-
$start_page = $max_page - $pages_to_show_minus_1;
337-
$end_page = $max_page;
338-
}
339-
if($start_page <= 0) {
340-
$start_page = 1;
341-
}
342-
echo $before.'<nav class="page-navigation"><ol class="bones_page_navi clearfix">'."";
343-
if ($start_page >= 2 && $pages_to_show < $max_page) {
344-
$first_page_text = __( "First", 'bonestheme' );
345-
echo '<li class="bpn-first-page-link"><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>';
346-
}
347-
echo '<li class="bpn-prev-link">';
348-
previous_posts_link('<<');
349-
echo '</li>';
350-
for($i = $start_page; $i <= $end_page; $i++) {
351-
if($i == $paged) {
352-
echo '<li class="bpn-current">'.$i.'</li>';
353-
} else {
354-
echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
355-
}
356-
}
357-
echo '<li class="bpn-next-link">';
358-
next_posts_link('>>');
359-
echo '</li>';
360-
if ($end_page < $max_page) {
361-
$last_page_text = __( "Last", 'bonestheme' );
362-
echo '<li class="bpn-last-page-link"><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>';
363-
}
364-
echo '</ol></nav>'.$after."";
312+
function bones_page_navi() {
313+
global $wp_query;
314+
$bignum = 999999999;
315+
if ( $wp_query->max_num_pages <= 1 )
316+
return;
317+
318+
echo '<nav class="pagination">';
319+
320+
echo paginate_links( array(
321+
'base' => str_replace( $bignum, '%#%', esc_url( get_pagenum_link($bignum) ) ),
322+
'format' => '',
323+
'current' => max( 1, get_query_var('paged') ),
324+
'total' => $wp_query->max_num_pages,
325+
'prev_text' => '&larr;',
326+
'next_text' => '&rarr;',
327+
'type' => 'list',
328+
'end_size' => 3,
329+
'mid_size' => 3
330+
) );
331+
332+
echo '</nav>';
365333
} /* end page navi */
366334

367335
/*********************

library/scss/_base.scss

Lines changed: 35 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -401,97 +401,44 @@ POSTS & CONTENT STYLES
401401
PAGE NAVI STYLES
402402
******************************************************************/
403403

404-
.page-navigation,
404+
.pagination,
405405
.wp-prev-next {
406406
margin: 1.1em 0 2.2em;
407407
}
408-
.bones_page_navi {
409-
410-
li {
411-
float: left;
412-
margin-left: 10px;
413-
414-
a {
415-
padding: 3px 6px;
416-
display: block;
417-
text-decoration: none;
418-
position: relative;
419-
420-
&:hover,
421-
&:focus {
422-
color: #f01d4f;
423-
text-decoration: underline;
424-
}
425-
}
426-
427-
}
428-
429-
/* current page link */
430-
li.bpn-current {
431-
padding: 3px 6px;
432-
border-bottom: 2px solid #f01d4f;
433-
position: relative;
434-
435-
a {
436-
/* hovering on current page link */
437-
&:hover,
438-
&:focus {}
439-
440-
}
441-
442-
} /* end .bones_page_navi .bpn-current */
443-
444-
/* common styles for page-navi links */
445-
li.bpn-prev-link,
446-
li.bpn-next-link {
447-
font-weight: 700;
448-
449-
a {
450-
padding: 0;
451-
}
452-
}
453-
454-
/* remove the bg on end links */
455-
li.bpn-prev-link a:hover,
456-
li.bpn-next-link a:hover,
457-
li.bpn-first-page-link a:hover,
458-
li.bpn-last-page-link a:hover {
459-
background: none;
460-
}
461-
462-
/* previous link */
463-
li.bpn-prev-link {
464-
a {
465-
&:hover,
466-
&:focus {}
467-
}
468-
}
469-
470-
/* next page link */
471-
li.bpn-next-link {
472-
a {
473-
&:hover,
474-
&:focus {}
475-
}
476-
}
477-
478-
/* first page link */
479-
li.bpn-first-page-link {
480-
a {
481-
&:hover,
482-
&:focus {}
483-
}
484-
}
485-
486-
/* last page link */
487-
li.bpn-last-page-link {
488-
a {
489-
&:hover,
490-
&:focus {}
491-
}
492-
}
493-
494-
} /* end .bones_page_navi */
408+
.pagination{
409+
text-align: center;
410+
ul {
411+
display: inline-block;
412+
white-space: nowrap;
413+
padding:0;
414+
clear: both;
415+
margin: 1px;
416+
li {
417+
padding: 0;
418+
margin: 0;
419+
float: left;
420+
display: inline;
421+
overflow: hidden;
422+
a, span {
423+
margin: 0;
424+
text-decoration: none;
425+
padding: 0;
426+
line-height: 1em;
427+
font-size: 1em;
428+
font-weight: normal;
429+
padding: .5em;
430+
min-width: 1em;
431+
display: block;
432+
}
433+
span.current{
434+
font-weight: bold;
435+
}
436+
a:hover, a:focus {
437+
438+
}
439+
}
440+
}
441+
} /* end .bones_page_navi */
495442

496443
/* fallback previous & next links */
497444
.wp-prev-next {

0 commit comments

Comments
 (0)