我有一个自定义分页,使用带有get操作的表单,这样我就可以有一个页面跳转框。在您输入非实际页面之前,一切都正常。例如负数、文本或大于实际页数的数字。
我要做的是截取变量,如果页面不存在,则重定向页面。
这是我的职责。php
add_action(\'init\', \'k2wp_pagination\');
function k2wp_pagination($k2url = \'\', $pages = \'\', $range = 2) {
$showitems = ($range * 2) + 1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == \'\') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages) {
$pages = 1;
}
}
if(1 != $pages) {
echo \'<div class="pagination-wrapper clearfix">\';
echo \'<form action="\' . get_bloginfo(\'url\') .\'/\'. $k2url . \'" class="pagination-buttons" method="get">\';
echo \'<div class="pager-buttons btn-group">\';
if($paged > 2 && $paged > $range + 1 && $showitems < $pages) echo \'<button value="1" name="paged" class="btn">« First</button>\';
if($paged > 1 && $showitems < $pages) echo \'<button value="\' . ($paged - 1) . \'" name="paged" class="btn"><i class="icon-angle-left"></i></button>\';
for ($i=1; $i <= $pages; $i++) {
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
echo ($paged == $i)? \'<button value="\' . $i . \'" name="paged" class="btn disabled" disabled="disabled">\' . $i . \'</button>\' : \'<button value="\' . $i . \'" name="paged" class="btn">\' . $i . \'</button>\';
}
}
if ($paged < $pages && $showitems < $pages) echo \'<button value="\' . ($paged + 1) . \'" name="paged" class="btn"><i class="icon-angle-right"></i></button>\';
if ($paged < $pages-1 && $paged + $range - 1 < $pages && $showitems < $pages) echo \'<button value="\' . $pages . \'" name="paged" class="btn">Last »</button>\';
echo \'</div>\';
echo \'</form>\';
echo \'<form action="\' . get_bloginfo(\'url\') .\'/\'. $k2url . \'" class="pagination-jump" method="get">\';
echo \'<div class="pager-jump">Page <input alt="Enter page to which you wish to jump" name="paged" type="text" value="\' . $paged . \'" class="jumper"> of \' . $pages . \' <button class="btn">Go</button></div>\';
echo \'</form>\';
echo \'</div>\';
}
}