Added pagination function
Showing
1 changed file
with
32 additions
and
0 deletions
| ... | @@ -134,6 +134,38 @@ function add_settings_fields($class, $page = 'general', $section = 'default') { | ... | @@ -134,6 +134,38 @@ function add_settings_fields($class, $page = 'general', $section = 'default') { |
| 134 | } | 134 | } |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | function pagination($pages = null, $range = 2, $before = '', $after = '') { | ||
| 138 | $showitems = ($range * 2) + 1; | ||
| 139 | |||
| 140 | $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | ||
| 141 | |||
| 142 | if(is_null($pages)) { | ||
| 143 | global $wp_query; | ||
| 144 | $pages = $wp_query->max_num_pages; | ||
| 145 | if (!$pages) { | ||
| 146 | $pages = 1; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | if (1 != $pages) { | ||
| 151 | echo $before; | ||
| 152 | |||
| 153 | if ($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='" . get_pagenum_link(1)."'>«</a>"; | ||
| 154 | if ($paged > 1 && $showitems < $pages) echo "<a href='" . get_pagenum_link($paged - 1) . "'>‹</a>"; | ||
| 155 | |||
| 156 | for ($i = 1; $i <= $pages; $i++) { | ||
| 157 | if (1 != $pages && (!($i >= $paged + $range + 1 || $i <= $paged-$range-1) || $pages <= $showitems)) { | ||
| 158 | echo ($paged == $i) ? "<span class='current'>" . $i . "</span>":"<a href='" . get_pagenum_link($i) . "' class='inactive' >" . $i . "</a>"; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | if ($paged < $pages && $showitems < $pages) echo "<a href='" . get_pagenum_link($paged + 1) . "'>›</a>"; | ||
| 163 | if ($paged < $pages-1 && $paged+$range - 1 < $pages && $showitems < $pages) echo "<a href='" . get_pagenum_link($pages) . "'>»</a>"; | ||
| 164 | |||
| 165 | echo $after; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 137 | class Vars { | 169 | class Vars { |
| 138 | public static $loaded = Array(); | 170 | public static $loaded = Array(); |
| 139 | } | 171 | } | ... | ... |
-
Please register or sign in to post a comment