-
Notifications
You must be signed in to change notification settings - Fork 9
/
tl-template-tags.php
169 lines (142 loc) · 3.35 KB
/
tl-template-tags.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* Return not found text
*
* @package The_Loops
* @since 0.3
*
* @param int $tl_loop_id Loop ID.
*/
function tl_not_found_text( $tl_loop_id = 0, $echo = true ) {
if ( empty( $the_loop_id ) )
global $the_loop_id;
$content = tl_get_loop_parameters( $the_loop_id );
if ( $echo )
echo $content['not_found'];
else
return $content['not_found'];
}
/**
* Return pagination
*
* @package The_Loops
* @since 0.3
*
* @param int $tl_loop_id Loop ID
*/
function tl_pagination( $the_loop_id = 0, $echo = true ) {
global $wp_query, $tl_user_query;
if ( empty( $the_loop_id ) )
global $the_loop_id;
$pagination = '';
$content = tl_get_loop_parameters( $the_loop_id );
$type = tl_get_loop_object_type( $the_loop_id );
if ( ! tl_in_widget() && ! empty( $content['pagination'] ) ) {
$paged = max( 1, get_query_var('paged') );
if ( 'users' == $type )
$total = ceil( $tl_user_query->get_total() / $content['number'] );
else
$total = $wp_query->max_num_pages;
switch ( $content['pagination'] ) {
case 'numeric' :
$pagination = paginate_links( array(
'base' => str_replace( 999999999, '%#%', get_pagenum_link( 999999999 ) ),
'format' => '?paged=%#%',
'current' => $paged,
'total' => $total
) );
break;
case 'previous_next' :
if ( 'users' == $type ) {
$links = array();
if ( 1 < $total ) {
if ( 1 < $paged ) {
$link = get_pagenum_link( $paged - 1 );
$links[] = '<a class="prev" href="' . esc_url( $link ) . '">' . __( '« Previous Page' ) . '</a>';
}
if ( $paged < $total ) {
$link = get_pagenum_link( $paged + 1 );
$links[] = '<a class="next" href="' . esc_url( $link ) . '">' . __( 'Next Page »' ) . '</a>';
}
$pagination = implode( ' — ', $links );
}
} else {
$pagination = get_posts_nav_link();
}
break;
default:
break;
}
}
if ( $echo )
echo $pagination;
else
return $pagination;
}
/**
* Check if current loop is in a widget
*
* @package The_Loops
* @since 0.3
*/
function tl_in_widget() {
global $the_loop_context;
return 'widget' == $the_loop_context;
}
/**
* Whether there are more users available in the loop.
*
* @package The_Loops
* @since 0.4
*
* @return bool True if users are available, false if end of loop.
*/
function tl_have_users() {
global $tl_user_query, $tl_index, $tl_count;
if ( null === $tl_index ) {
$tl_index = -1;
$tl_user_query->results = array_values( $tl_user_query->results );
$tl_count = count( $tl_user_query->results );
}
if ( $tl_index + 1 < $tl_count )
return true;
elseif ( $tl_index + 1 == $tl_count && $tl_count > 0 )
tl_rewind_users();
return false;
}
/**
* Reset user index.
*
*
* @package The_Loops
* @since 0.4
*/
function tl_rewind_users() {
global $tl_user_query, $tl_index, $tl_count;
unset( $tl_index, $tl_count );
}
/**
* Sets up the current user.
*
* Retrieves the next user, sets up the user
*
* @package The_Loops
* @since 0.4
*/
function tl_the_user() {
$user = tl_next_user();
wp_set_current_user( $user->ID );
}
/**
* Set up the next user and iterate current user index.
*
* @package The_Loops
* @since 0.4
*
* @return object Next user.
*/
function tl_next_user() {
global $tl_user_query, $tl_index;
$tl_index++;
return $tl_user_query->results[$tl_index];
}