Last active
December 12, 2015 08:48
-
-
Save hbsnow/4746454 to your computer and use it in GitHub Desktop.
wordpress のページング用関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 結果を出力する場所に <?php paging_numbers(); ?> を挿入することで希望する位置にナビゲーションを出力することができる | |
function paging_numbers(){ | |
global $wp_rewrite, $wp_query, $paged; | |
if(($wp_query->max_num_pages) > 1): | |
if (strpos(($paginate_base = get_pagenum_link(1)), '?') || ! $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), | |
'type' => 'list', | |
)); | |
echo "<nav>$result</nav>"; | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment