我想我已经通过使用get_posts
在内部this pagination function 作者:Kriesi。
代码的主要核心在functions.php
我正在调用single
模板如下:kriesi_pagination($additional_loop->max_num_pages);
function kriesi_pagination($pages = \'\', $range = 3) {
global $post;
$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\'><ul id=\'post-timeline\'>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href=\'".get_pagenum_link(1)."\'>«</a>";
if($paged > 1 && $showitems < $pages) echo "<a href=\'".get_pagenum_link($paged - 1)."\'>‹</a>";
$args = array( \'numberposts\' => $pages, \'post_status\'=> \'publish\' );
$myposts = get_posts( $args );
for ($i=1; $i <= $pages; $i++) {
$p = $i-1;
$entryDay = date(\'j\', strtotime($myposts[$p]->post_date));
$entryMon = date(\'M\', strtotime($myposts[$p]->post_date));
//$newID = $myposts[$p]->post_date(\'j,M\');
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
echo ($paged == $i)? "<li class=\'current\'><span class=\'day\'>".$entryDay."</span><br/><span class=\'small\'>".$entryMon."</span></li>":"<li class=\'timeline\'><a href=\'".get_pagenum_link($i)."\' class=\'inactive\' ><span class=\'day\'>".$entryDay."</span><br/><span class=\'small\'>".$entryMon."</span></a></li>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href=\'".get_pagenum_link($paged + 1)."\'>›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href=\'".get_pagenum_link($pages)."\'>»</a>";
echo "</ul></div>\\n";
}
}
如果有人对此代码有任何反馈,是否可以使用
get_posts
沿着
for
以这种方式循环,或者如果有更好的方法,请让我知道!
谢谢