forked from xserver-inc/cocoon
/
pagination.php
74 lines (67 loc) · 2.39 KB
/
pagination.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php //「次のページ」ページネーション
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/
if ( !defined( 'ABSPATH' ) ) exit;
//現在のページ番号
global $paged;
if(empty($paged)) $paged = 1;
//ページ情報の取得
global $wp_query;
//全ページ数
$pages = $wp_query->max_num_pages;
if(!$pages){
$pages = 1;
}
//1ページかどうか
$is_1_page = ($pages != 1);
//ページが1ページしかない場合は出力しない
if($is_1_page) {
//次のページ番号
if ( $pages == $paged ) {
$next_page_num = $paged;
} else {
$next_page_num = $paged + 1;
}
//現在のページ番号が全ページ数よりも少ないときは「次のページ」タグを出力
if ( $paged < $pages ) {
$url = get_pagenum_link($next_page_num);
//$url = get_query_removed_url($url);
// var_dump($url);
echo '<div class="pagination-next"><a href="'.esc_url($url).'" class="pagination-next-link key-btn">'.apply_filters('pagination_next_link_caption', __( '次のページ', THEME_NAME )).'</a></div>';
}
}
//ページが1ページしかない場合は出力しない
if($is_1_page):
?>
<div class="pagination">
<?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','%#%', get_requested_url());
}
else{
$pagenum_link = html_entity_decode( get_pagenum_link() );
$url = get_pagenum_link(2);
$string = str_replace(trailingslashit($pagenum_link), '', $url);
$string = str_replace(user_trailingslashit('/2'), '/%#%/', $string);
$paginate_format = (substr($paginate_base,-1,1) == '/' ? '' : '/') .
user_trailingslashit($string, 'paged');
$paginate_base .= '%_%';
}
echo paginate_links(array(
'base' => $paginate_base,
'format' => $paginate_format,
'total' => $wp_query->max_num_pages,
'mid_size' => 2,
'current' => ($paged ? $paged : 1),
'prev_text' => '<span class="screen-reader-text">'.__( '前へ', THEME_NAME ).'</span><span class="fa fa-angle-left" aria-hidden="true"></span>',
'next_text' => '<span class="screen-reader-text">'.__( '次へ', THEME_NAME ).'</span><span class="fa fa-angle-right" aria-hidden="true"></span>',
)); ?>
</div><!-- /.pagination -->
<?php
endif;