-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop-navigation.php
110 lines (77 loc) · 3.13 KB
/
loop-navigation.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Output navigation at bottom of single and multiple loops
*/
// No direct access
if ( ! defined( 'ABSPATH' ) ) exit;
do_action('uplifted_before_navigation');
/*********************************
* ATTACHMENT - Back to Parent
*********************************/
// No prev/next for gallery images since images can belong to multiple galleries.
// Instead, a lightbox plugin like Jetpack Carousel can be used for prev/next.
if ( is_attachment() ) :
?>
<?php
if ( ! empty( $post->post_parent ) && $parent_post = get_post( $post->post_parent ) ) : ?>
<nav class="pagination attachment-pagination">
<div class="uplifted-nav-left"><?php previous_post_link( '%link', sprintf( __( '← Back to %s', 'uplifted' ), $parent_post->post_title ) ); ?></div>
</nav>
<?php endif; ?>
<?php
/*********************************
* SINGLE POST - Prev / Next
*********************************/
elseif ( is_singular() && ! uplifted_loop_after_content_used() ) : // use Multiple Posts nav on "loop after content" pages
?>
<?php
// Let child themes change this
$prev_next_title_characters = apply_filters( 'uplifted_prev_next_title_characters', 25 );
// no nav for regular pages
if ( ! is_page() ) :
?>
<nav class="uplifted-nav-left-right pagination">
<?php if ( $prev_post = get_previous_post() ) : ?>
<div class="uplifted-nav-left">
<?php
/* translators: %1$s is left arrow icon, %2$s is post title */
previous_post_link( '%link', sprintf( _x( '← %1$s', 'previous post link', 'uplifted' ), ctfw_shorten( $prev_post->post_title, $prev_next_title_characters ) ) );
?>
</div>
<?php endif; ?>
<?php if ( $next_post = get_next_post() ) : ?>
<div class="uplifted-nav-right">
<?php
/* translators: %1$s is post title, %2$s is right arrow icon */
next_post_link( '%link', sprintf( _x( '%1$s →', 'next post link', 'uplifted' ), ctfw_shorten( $next_post->post_title, $prev_next_title_characters ) ) );
?>
</div>
<?php endif; ?>
</nav>
<?php endif; ?>
<?php
/*********************************
* MULTIPLE POSTS - Page 1 2 3
*********************************/
else :
// Query to use for pagination
if ( ! ( $query = uplifted_loop_after_content_query() ) ) { // use "loop after content" query if available
$query = $wp_query; // otherwise use default query
}
?>
<?php if ( $query->max_num_pages > 1 ) : // show only if more than 1 page ?>
<nav class="pagination">
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ), // for search and archives: https://codex.wordpress.org/Function_Reference/paginate_links#Examples
'current' => max( 1, ctfw_page_num() ), // ctfw_page_num() returns/corrects $paged so pagination works on static front page
'total' => $query->max_num_pages,
'type' => 'list',
'prev_text' => sprintf( _x( '← %s Previous', 'pagination', 'uplifted' ), $icon_left ),
'next_text' => sprintf( _x( 'Next %s →', 'pagination', 'uplifted' ), $icon_right ),
) );
?>
</nav>
<?php endif; ?>
<?php endif; ?>
<?php do_action('uplifted_after_navigation'); ?>