akiyum
4/22/2014 - 3:25 AM

ページナビ出力

ページナビ出力

/*ページナビ出力*/
function pagenavi( $p = 3 ) {
  if ( is_singular() ) return;
  global $wp_query, $paged;
  $max_page = $wp_query->max_num_pages;
  if ( $max_page == 1 ) return;
  if ( empty( $paged ) ) $paged = 1;
  previous_posts_link( '<span class="previouspostslink">前へ</span>' );
  if ( $paged > $p + 1 ) p_link( 1, 'First' );
  if ( $paged > $p + 2 ) echo '<span class="extend">...</span> ';
  for( $i = $paged - $p; $i <= $paged + $p; $i++ ) {
    if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<span class='page current'>{$i}</span> " : p_link( $i );
  }
  if ( $paged < $max_page - $p - 1 ) echo '<span class="extend">...</span> ';
  if ( $paged < $max_page - $p ) p_link( $max_page, 'Last' );
  next_posts_link( '<span class="nextpostslink">次へ</span>' );
}
function p_link( $i, $title = '' ) {
  if ( $title == '' ) $title = "Page {$i}";
  echo "<a class='page' href='", esc_html( get_pagenum_link( $i ) ), "' title='{$title}'>{$i}</a> ";
}