/*------------------------------------------------ --------------------- * 此站点的分页。
-------------------------------------------------- ------------------- /
功能 geigerakademie_posts_paginate($args = false) {
$type = 'posts';
$options = array();
$previouspage = '«';
$nextpage = '»';
$before = '<div class="paging clearfix">';
$after = '</div>';
$range = 3;
$title = '';
$anchor = 1;
$gap = 1;
$r = wp_parse_args($args, $options);
extract($r, EXTR_SKIP);
if (!isset($page) && !isset($pages)) {
global $wp_query;
if ($type === 'posts') {
$page = get_query_var('paged');
$posts_per_page = intval(get_query_var('posts_per_page'));
$pages = intval(ceil($wp_query->found_posts / $posts_per_page));
}
else {
$page = get_query_var('cpage');
$comments_per_page = get_option('comments_per_page');
$pages = get_comment_pages_count();
}
$page = !empty($page) ? intval($page) : 1;
}
$prevlink = ($type === 'posts')
? esc_url(get_pagenum_link($page - 1))
: get_comments_pagenum_link($page - 1);
$nextlink = ($type === 'posts')
? esc_url(get_pagenum_link($page + 1))
: get_comments_pagenum_link($page + 1);
$output = stripslashes($before);
if ($pages > 1) {
$ellipsis = "<a class='gap'>...</a>";
if ($page > 1 && !empty($previouspage)) {
$output .= sprintf('<a class="page-prev" href="%s"><span> </span></a>', $prevlink);
}
$min_links = $range * 2 + 1;
$block_min = min($page - $range, $pages - $min_links);
$block_high = max($page + $range, $min_links);
$left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
$right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;
if ($left_gap && !$right_gap) {
$output .= sprintf('%s%s%s',
geigerakademie_posts_paginate_loop(1, $anchor),
$ellipsis,
geigerakademie_posts_paginate_loop($block_min, $pages, $page)
);
}
else if ($left_gap && $right_gap) {
$output .= sprintf('%s%s%s%s%s',
geigerakademie_posts_paginate_loop(1, $anchor),
$ellipsis,
geigerakademie_posts_paginate_loop($block_min, $block_high, $page),
$ellipsis,
geigerakademie_posts_paginate_loop(($pages - $anchor + 1), $pages)
);
}
else if ($right_gap && !$left_gap) {
$output .= sprintf('%s%s%s',
geigerakademie_posts_paginate_loop(1, $block_high, $page),
$ellipsis,
geigerakademie_posts_paginate_loop(($pages - $anchor + 1), $pages)
);
}
else {
$output .= geigerakademie_posts_paginate_loop(1, $pages, $page);
}
if ($page < $pages && !empty($nextpage)) {
$output .= sprintf('<a class="page-next" href="%s"><span> </span></a>', $nextlink);
}
$output .= "</ol>";
}
$output .= stripslashes($after);
if ($pages > 1 || $empty) {
echo $output;
}
}
功能 geigerakademie_posts_paginate_loop($start, $max, $page = 0) {
$type = 'posts';
$output = "";
for ($i = $start; $i <= $max; $i++) {
$p = ($type === 'posts') ? esc_url(get_pagenum_link($i)) : get_comments_pagenum_link($i);
$output .= ($page == intval($i))
? "<a class='page current' href='javascript:void(0)'>$i</a></span>"
: "<a href='$p' title='$i' class='page'>$i</a>";
}
return $output;
}