2009
09.21

functions.php

/*ページナビ---------------------------------------------*/

function bmPageNavi() {
  global $wp_rewrite;
  global $wp_query;
  global $paged;
  $paginate_base = get_pagenum_link(1);
  if (strpos($paginate_base, '?') || ! $wp_rewrite->using_permalinks()) {
	$paginate_format = '';
	$paginate_base = add_query_arg('paged', '%#%');
  } else {
	$paginate_format = (substr($paginate_base, -1 ,1) == '/' ? '' : '/') .
	user_trailingslashit('page/%#%/', 'paged');;
	$paginate_base .= '%_%';
  }
  $result = paginate_links( array(
	'base' => $paginate_base,
	'format' => $paginate_format,
	'total' => $wp_query->max_num_pages,
	'mid_size' => 5,
	'current' => ($paged ? $paged : 1),
  ));
  return $result;
}

/*ページナビ---------------------------------------------*/

function paginate_links2( $args = '' ) {
	$defaults = array(
		'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
		'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
		'total' => 1,
		'current' => 0,
		'show_all' => false,
		'prev_next' => true,
		'prev_text' => __('« Previous'),
		'next_text' => __('Next »'),
		'end_size' => 1,
		'mid_size' => 2,
		'type' => 'plain',
		'add_args' => false, // array of query args to add
		'add_fragment' => ''
	);

	$args = wp_parse_args( $args, $defaults );
	extract($args, EXTR_SKIP);

	// Who knows what else people pass in $args
	$total = (int) $total;
	if ( $total < 2 )
		return;
	$current  = (int) $current;
	$end_size = 0  < (int) $end_size ? (int) $end_size : 1; // Out of bounds?  Make it the default.
	$mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
	$add_args = is_array($add_args) ? $add_args : false;
	$r = '';
	$page_links = array();
	$n = 0;
	$dots = false;

	if ( $prev_next && $current && 1 < $current ) :
		$link = str_replace('%_%', 2 == $current ? '' : $format, $base);
		$link = str_replace('%#%', $current - 1, $link);
		if ( $add_args )
			$link = add_query_arg( $add_args, $link );
		$link .= $add_fragment;
		$page_links[] = "<li class='prev page-numbers'><a class='span' href='" . clean_url($link) . "'>$prev_text</a></li>";
	endif;
	for ( $n = 1; $n <= $total; $n++ ) :
		$n_display = number_format_i18n($n);
		if ( $n == $current ) :
			$page_links[] = "<li class='page-numbers current'><span class='span'>$n_display</span></li>";
			$dots = true;
		else :
			if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
				$link = str_replace('%_%', 1 == $n ? '' : $format, $base);
				$link = str_replace('%#%', $n, $link);
				if ( $add_args )
					$link = add_query_arg( $add_args, $link );
				$link .= $add_fragment;
				$page_links[] = "<li class='page-numbers'><a class='span' href='" . clean_url($link) . "'>$n_display</a>";
				$dots = true;
			elseif ( $dots && !$show_all ) :
				$page_links[] = "<li class='prev page-numbers dots'><span class='span'>...</span></li>";
				$dots = false;
			endif;
		endif;
	endfor;
	if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
		$link = str_replace('%_%', $format, $base);
		$link = str_replace('%#%', $current + 1, $link);
		if ( $add_args )
			$link = add_query_arg( $add_args, $link );
		$link .= $add_fragment;
		$page_links[] = "<li class='next page-numbers'><a class='span' href='" . clean_url($link) . "'>$next_text</a></li>";
	endif;
	switch ( $type ) :
		case 'array' :
			return $page_links;
			break;
		case 'list' :
			$r .= "<ul class='page-numbers'>\n\t<li>";
			$r .= join("</li>\n\t<li>", $page_links);
			$r .= "</li>\n</ul>\n";
			break;
		default :
			$r = join("\n", $page_links);
			break;
	endswitch;
	
	$r = "<div class='pageNavigation clearfix'>\n<ul class='clearfix'>\n".$r."\n</ul>\n</div>";

	return $r;
}

category-*.php

<?php query_posts($query_string.'&cat=5&posts_per_page=5'); ?>
	<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>

	<?php endwhile; ?>

	<?php global $wp_rewrite;
	$paginate_base = get_pagenum_link(1);
	if (strpos($paginate_base, '?') || ! $wp_rewrite->using_permalinks()) {
		$paginate_format = '';
		$paginate_base = add_query_arg('paged', '%#%');
	} else {
		$paginate_format = (substr($paginate_base, -1 ,1) == '/' ? '' : '/') .
		user_trailingslashit('page/%#%/', 'paged');;
		$paginate_base .= '%_%';
	}
	echo paginate_links2( array(
		'base' => $paginate_base,
		'format' => $paginate_format,
		'total' => $wp_query->max_num_pages,
		'mid_size' => 5,
		'current' => ($paged ? $paged : 1),
	)); ?>

<?php endif; ?>
<?php wp_reset_query(); ?>

※query_postsを、
query_posts($query_string.’&cat=5&posts_per_page=5′)
と書かないとだめ

css

/*- ページナビ */
div.pageNavigation {
	margin: 5px 5px 5px 5px;
	clear: both;
}
div.pageNavigation ul {
	float: right;
}
div.pageNavigation li {
	float: left;
	margin: 1px;
	text-align: center;
}
div.pageNavigation a {
	/*文字*/
	color: #FFFFFF;
}
div.pageNavigation li a.span,
div.pageNavigation li span.span {
	/*ページ数部分*/
	display: block;
	padding: 2px 5px 0px 5px;
	text-decoration:none;
	color: #FFFFFF;
	background: #333333;
	b order: 1px solid #666666;
}
div.pageNavigation li.current .span {
	/*カレントページのページ数部分*/
	color: #000000;
	background: #CCCCCC;
	b order: 1px solid #666666;
}
div.pageNavigation li.next .span,
div.pageNavigation li.prev .span {
	/*次へ、前へ*/
	color: #FFFFFF;
	background: #333333;
	b order: 1px solid #666666;
}
div.pageNavigation li.page-numbers a:hover.span {
	/*ホバー時*/
	color: #000000;
	background: #CCCCCC;
}

No Comment.

Add Your Comment