Jelajahi Sumber

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>
Gabriel Luethje 12 tahun lalu
induk
melakukan
bb68b740ef
2 mengubah file dengan 56 tambahan dan 141 penghapusan
  1. 21 53
      library/bones.php
  2. 35 88
      library/scss/_base.scss

+ 21 - 53
library/bones.php

@@ -309,59 +309,27 @@ PAGE NAVI
 *********************/
 
 // Numeric Page Navi (built into the theme by default)
-function bones_page_navi($before = '', $after = '') {
-	global $wpdb, $wp_query;
-	$request = $wp_query->request;
-	$posts_per_page = intval(get_query_var('posts_per_page'));
-	$paged = intval(get_query_var('paged'));
-	$numposts = $wp_query->found_posts;
-	$max_page = $wp_query->max_num_pages;
-	if ( $numposts <= $posts_per_page ) { return; }
-	if(empty($paged) || $paged == 0) {
-		$paged = 1;
-	}
-	$pages_to_show = 7;
-	$pages_to_show_minus_1 = $pages_to_show-1;
-	$half_page_start = floor($pages_to_show_minus_1/2);
-	$half_page_end = ceil($pages_to_show_minus_1/2);
-	$start_page = $paged - $half_page_start;
-	if($start_page <= 0) {
-		$start_page = 1;
-	}
-	$end_page = $paged + $half_page_end;
-	if(($end_page - $start_page) != $pages_to_show_minus_1) {
-		$end_page = $start_page + $pages_to_show_minus_1;
-	}
-	if($end_page > $max_page) {
-		$start_page = $max_page - $pages_to_show_minus_1;
-		$end_page = $max_page;
-	}
-	if($start_page <= 0) {
-		$start_page = 1;
-	}
-	echo $before.'<nav class="page-navigation"><ol class="bones_page_navi clearfix">'."";
-	if ($start_page >= 2 && $pages_to_show < $max_page) {
-		$first_page_text = __( "First", 'bonestheme' );
-		echo '<li class="bpn-first-page-link"><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>';
-	}
-	echo '<li class="bpn-prev-link">';
-	previous_posts_link('<<');
-	echo '</li>';
-	for($i = $start_page; $i  <= $end_page; $i++) {
-		if($i == $paged) {
-			echo '<li class="bpn-current">'.$i.'</li>';
-		} else {
-			echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
-		}
-	}
-	echo '<li class="bpn-next-link">';
-	next_posts_link('>>');
-	echo '</li>';
-	if ($end_page < $max_page) {
-		$last_page_text = __( "Last", 'bonestheme' );
-		echo '<li class="bpn-last-page-link"><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>';
-	}
-	echo '</ol></nav>'.$after."";
+function bones_page_navi() {
+	global $wp_query;
+	$bignum = 999999999;
+	if ( $wp_query->max_num_pages <= 1 )
+	return;
+	
+	echo '<nav class="pagination">';
+	
+		echo paginate_links( array(
+			'base' 			=> str_replace( $bignum, '%#%', esc_url( get_pagenum_link($bignum) ) ),
+			'format' 		=> '',
+			'current' 		=> max( 1, get_query_var('paged') ),
+			'total' 		=> $wp_query->max_num_pages,
+			'prev_text' 	=> '&larr;',
+			'next_text' 	=> '&rarr;',
+			'type'			=> 'list',
+			'end_size'		=> 3,
+			'mid_size'		=> 3
+		) );
+	
+	echo '</nav>';
 } /* end page navi */
 
 /*********************

+ 35 - 88
library/scss/_base.scss

@@ -401,97 +401,44 @@ POSTS & CONTENT STYLES
 PAGE NAVI STYLES
 ******************************************************************/
 
-.page-navigation,
+.pagination,
 .wp-prev-next {
 	margin: 1.1em 0 2.2em;
 }
-	.bones_page_navi {
-
-		li {
-			float: left;
-			margin-left: 10px;
-
-			a {
-				padding: 3px 6px;
-				display: block;
-				text-decoration: none;
-				position: relative;
-
-				&:hover,
-				&:focus {
-					color: #f01d4f;
-					text-decoration: underline;
-				}
-			}
-
-		}
-
-		/* current page link */
-		li.bpn-current {
-			padding: 3px 6px;
-			border-bottom: 2px solid #f01d4f;
-			position: relative;
-
-			a {
-				/* hovering on current page link */
-				&:hover,
-				&:focus {}
-
-			}
-
-		} /* end .bones_page_navi .bpn-current */
-
-		/* common styles for page-navi links */
-		li.bpn-prev-link,
-		li.bpn-next-link {
-			font-weight: 700;
-
-			a {
-				padding: 0;
-			}
-		}
-
-		/* remove the bg on end links */
-		li.bpn-prev-link a:hover,
-		li.bpn-next-link a:hover,
-		li.bpn-first-page-link a:hover,
-		li.bpn-last-page-link a:hover {
-			background: none;
-		}
-
-		/* previous link */
-		li.bpn-prev-link {
-			a {
-				&:hover,
-				&:focus {}
-			}
-		}
-
-		/* next page link */
-		li.bpn-next-link {
-			a {
-				&:hover,
-				&:focus {}
-			}
-		}
-
-		/* first page link */
-		li.bpn-first-page-link {
-			a {
-				&:hover,
-				&:focus {}
-			}
-		}
-
-		/* last page link */
-		li.bpn-last-page-link {
-			a {
-				&:hover,
-				&:focus {}
-			}
-		}
-
-	} /* end .bones_page_navi */
+	.pagination{
+        text-align: center;
+        ul {
+            display: inline-block;
+            white-space: nowrap;
+            padding:0;
+            clear: both;
+            margin: 1px;
+            li {
+                padding: 0;
+                margin: 0;
+                float: left;
+                display: inline;
+                overflow: hidden;
+                a, span {
+                    margin: 0;
+                    text-decoration: none;
+                    padding: 0;
+                    line-height: 1em;
+                    font-size: 1em;
+                    font-weight: normal;
+                    padding: .5em;
+                    min-width: 1em;
+                    display: block;
+                }
+                span.current{
+                	font-weight: bold;
+                }
+                a:hover, a:focus {
+                    
+                }
+            }
+        }
+    } /* end .bones_page_navi */
 
 	/* fallback previous & next links */
 	.wp-prev-next {