Changeset 2966 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/extras.php
- Timestamp:
- 04/15/2016 09:38:17 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/extras.php
r2799 r2966 141 141 add_filter( 'the_title', 'wporg_filter_archive_title', 10, 2 ); 142 142 add_filter( 'single_post_title', 'wporg_filter_archive_title', 10, 2 ); 143 144 /** 145 * Removes the query string from get_pagenum_link() for loop pagination. 146 * Fixes pagination links like example.com/?foo=bar/page/2/. 147 * 148 * @param array $args Arguments for the paginate_links() function. 149 * @return array Arguments for the paginate_links() function. 150 */ 151 function wporg_loop_pagination_args( $args ) { 152 global $wp_rewrite; 153 154 // Add the $base argument to the array if the user is using permalinks. 155 if ( $wp_rewrite->using_permalinks() && ! is_search() ) { 156 $pagenum = trailingslashit( preg_replace( '/\?.*/', '', get_pagenum_link() ) ); 157 $pagination_base = $wp_rewrite->pagination_base; 158 159 $args['base'] = user_trailingslashit( $pagenum . "{$pagination_base}/%#%" ); 160 } 161 162 return $args; 163 } 164 add_filter( 'loop_pagination_args', 'wporg_loop_pagination_args' ); 165 166 /** 167 * Removes 'page/1' from pagination links with a query string. 168 * 169 * @param string $page_links Page links HTML. 170 * @return string Page links HTML. 171 */ 172 function wporg_loop_pagination( $page_links ) { 173 global $wp_rewrite; 174 175 $pagination_base = $wp_rewrite->pagination_base; 176 $request = remove_query_arg( 'paged' ); 177 $query_string = explode( '?', $request ); 178 179 if ( isset( $query_string[1] ) ) { 180 181 $query_string = preg_quote( $query_string[1], '#' ); 182 183 // Remove 'page/1' from the entire output since it's not needed. 184 $page_links = preg_replace( 185 array( 186 "#(href=['\"].*?){$pagination_base}/1(\?{$query_string}['\"])#", // 'page/1' 187 "#(href=['\"].*?){$pagination_base}/1/(\?{$query_string}['\"])#", // 'page/1/' 188 ), 189 '$1$2', 190 $page_links 191 ); 192 } 193 194 return $page_links; 195 } 196 add_filter( 'loop_pagination', 'wporg_loop_pagination' ); 197
Note: See TracChangeset
for help on using the changeset viewer.