Make WordPress Core

Ticket #29808: 29808.2.diff

File 29808.2.diff, 9.0 KB (added by obenland, 10 years ago)
  • src/wp-includes/link-template.php

     
    21882188}
    21892189
    21902190/**
     2191 * Return navigation to next/previous post when applicable.
     2192 *
     2193 * @since 4.1.0
     2194 *
     2195 * @param array $args {
     2196 *     Default post navigation arguments. Optional.
     2197 *
     2198 *     @type string $prev_text Anchor text to display in the previous
     2199 *                             post link.
     2200 *     @type string $next_text Anchor text to display in the next post link.
     2201 * }
     2202 * @return string
     2203 */
     2204function get_the_post_navigation( $args = array() ) {
     2205        $args = wp_parse_args( $args, array(
     2206                'prev_text' => _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link' ),
     2207                'next_text' => _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link' ),
     2208        ) );
     2209
     2210        $navigation = '';
     2211        $previous   = get_previous_post_link( '<div class="nav-previous">%link</div>', $args['prev_text'] );
     2212        $next       = get_next_post_link( '<div class="nav-next">%link</div>', $args['next_text'] );
     2213
     2214        // Only add markup if there's somewhere to navigate to.
     2215        if ( $next || $previous ) {
     2216                $navigation = _navigation_markup( $next . $previous, 'post-navigation', __( 'Post navigation' ) );
     2217        }
     2218
     2219        return $navigation;
     2220}
     2221
     2222/**
     2223 * Display navigation to next/previous post when applicable.
     2224 *
     2225 * @since 4.1.0
     2226 *
     2227 * @param array $args {
     2228 *     Default post navigation arguments. Optional.
     2229 *
     2230 *     @type string $prev_text Anchor text to display in the previous
     2231 *                             post link.
     2232 *     @type string $next_text Anchor text to display in the next post link.
     2233 * }
     2234 */
     2235function the_post_navigation( $args = array() ) {
     2236        echo get_the_post_navigation( $args );
     2237}
     2238
     2239/**
     2240 * Return navigation to next/previous set of posts when applicable.
     2241 *
     2242 * @since 4.1.0
     2243 *
     2244 * @global WP_Query $wp_query WordPress Query object.
     2245 * @param array $args {
     2246 *     Default paging navigation arguments. Optional.
     2247 *
     2248 *     @type string $prev_text Anchor text to display in the previous
     2249 *                             posts link.
     2250 *     @type string $next_text Anchor text to display in the next posts link.
     2251 * }
     2252 * @return string
     2253 */
     2254function get_the_paging_navigation( $args = array() ) {
     2255        $navigation = '';
     2256
     2257        // Don't print empty markup if there's only one page.
     2258        if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
     2259                $args = wp_parse_args( $args, array(
     2260                        'prev_text' => __( '<span class="meta-nav">&larr;</span> Older posts' ),
     2261                        'next_text' => __( 'Newer posts <span class="meta-nav">&rarr;</span>' ),
     2262                ) );
     2263
     2264                $next_link = get_next_posts_link( $args['prev_text'] );
     2265                $prev_link = get_previous_posts_link( $args['next_text'] );
     2266
     2267                if ( $next_link ) {
     2268                        $navigation .= '<div class="nav-previous">' . $next_link . '</div>';
     2269                }
     2270
     2271                if ( $prev_link ) {
     2272                        $navigation .= '<div class="nav-next">' . $prev_link . '</div>';
     2273                }
     2274
     2275                $navigation = _navigation_markup( $navigation );
     2276        }
     2277
     2278        return $navigation;
     2279}
     2280
     2281/**
     2282 * Display navigation to next/previous set of posts when applicable.
     2283 *
     2284 * @since 4.1.0
     2285 * @uses get_paging_navigation()
     2286 *
     2287 * @param array $args {
     2288 *     Default paging navigation arguments. Optional.
     2289 *
     2290 *     @type string $prev_text Anchor text to display in the previous
     2291 *                             posts link.
     2292 *     @type string $next_text Anchor text to display in the next posts link.
     2293 * }
     2294 */
     2295function the_paging_navigation( $args = array() ) {
     2296        echo get_the_paging_navigation( $args );
     2297}
     2298
     2299/**
     2300 * Return a paginated navigation to next/previous set of posts,
     2301 * when applicable.
     2302 *
     2303 * @since 4.1.0
     2304 *
     2305 * @param array $args {
     2306 *     Default pagination arguments. Optional.
     2307 *
     2308 *     @type string $base      Url to be used to create the paginated links.
     2309 *                             Example: "http://example.com/all_posts.php%_%"
     2310 *                             The '%_%' is required and will be replaced by
     2311 *                             the contents of the 'format' argument.
     2312 *     @type string $format    Used to replace the page number.
     2313 *                             Example:"?page=%#%"
     2314 *                             The '%#%' is required and will be replaced with
     2315 *                             the page number.
     2316 *     @type int    $total     The total amount of pages.
     2317 *     @type int    $current   The current page number.
     2318 *     @type bool   $prev_next Whether to include previous and next links.
     2319 *                             Default: true.
     2320 *     @type string $prev_text Anchor text to display in the previous
     2321 *                             posts link.
     2322 *     @type string $next_text Anchor text to display in the next posts link.
     2323 *     @type bool   $show_all  Whether to show all pages.
     2324 *                             Default: false, shows short list of the pages
     2325 *                             near the current page.
     2326 *     @type int    $end_size  Amount of numbers on either the start and the
     2327 *                             end list edges.
     2328 *                             Default: 1.
     2329 *     @type int    $mid_size  Amount of numbers to either side of current page
     2330 *                             but not including current page.
     2331 *                             Default: 1.
     2332 *     @type array  $add_args  Query vars to be added to the links.
     2333 *     @type string $before_page_number Text to prepend to the anchor text.
     2334 *     @type string $after_page_number  Text to append to the anchor text.
     2335 * }
     2336 * @return string
     2337 */
     2338function get_the_pagination( $args = array() ) {
     2339        $navigation = '';
     2340
     2341        // Don't print empty markup if there's only one page.
     2342        if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
     2343                $args = wp_parse_args( $args, array(
     2344                        'mid_size'  => 1,
     2345                        'prev_text' => __( '&larr; Previous' ),
     2346                        'next_text' => __( 'Next &rarr;' ),
     2347                ) );
     2348                // Make sure we get plain links, so we can work with it.
     2349                $args['type'] = 'plain';
     2350
     2351                // Set up paginated links.
     2352                $links = paginate_links( $args );
     2353
     2354                if ( $links ) {
     2355                        $navigation = _navigation_markup( $links, 'pagination' );
     2356                }
     2357        }
     2358
     2359        return $navigation;
     2360}
     2361
     2362/**
     2363 * Display a paginated navigation to next/previous set of posts,
     2364 * when applicable.
     2365 *
     2366 * @since 4.1.0
     2367 *
     2368 * @param array $args {
     2369 *     Default pagination arguments. Optional.
     2370 *
     2371 *     @type string $base      Url to be used to create the paginated links.
     2372 *                             Example: "http://example.com/all_posts.php%_%"
     2373 *                             The '%_%' is required and will be replaced by
     2374 *                             the contents of the 'format' argument.
     2375 *     @type string $format    Used to replace the page number.
     2376 *                             Example:"?page=%#%"
     2377 *                             The '%#%' is required and will be replaced with
     2378 *                             the page number.
     2379 *     @type int    $total     The total amount of pages.
     2380 *     @type int    $current   The current page number.
     2381 *     @type bool   $prev_next Whether to include previous and next links.
     2382 *                             Default: true.
     2383 *     @type string $prev_text Anchor text to display in the previous
     2384 *                             posts link.
     2385 *     @type string $next_text Anchor text to display in the next posts link.
     2386 *     @type bool   $show_all  Whether to show all pages.
     2387 *                             Default: false, shows short list of the pages
     2388 *                             near the current page.
     2389 *     @type int    $end_size  Amount of numbers on either the start and the
     2390 *                             end list edges.
     2391 *                             Default: 1.
     2392 *     @type int    $mid_size  Amount of numbers to either side of current page
     2393 *                             but not including current page.
     2394 *                             Default: 1.
     2395 *     @type array  $add_args  Query vars to be added to the links.
     2396 *     @type string $before_page_number Text to prepend to the anchor text.
     2397 *     @type string $after_page_number  Text to append to the anchor text.
     2398 * }
     2399 */
     2400function the_pagination( $args = array() ) {
     2401        echo get_the_pagination( $args );
     2402}
     2403
     2404/**
     2405 * Wraps passed links in navigational markup.
     2406 *
     2407 * @since 4.1.0
     2408 * @access private
     2409 *
     2410 * @param string $links              Navigational links. Required.
     2411 * @param string $class              Custom class for nav element. Optional.
     2412 *                                   Default: 'paging-navigation'.
     2413 * @param string $screen_reader_text Screen reader text for nav element.
     2414 *                                   Optional.
     2415 * @return string
     2416 */
     2417function _navigation_markup( $links, $class = 'paging-navigation', $screen_reader_text = '' ) {
     2418        if ( empty( $screen_reader_text ) ) {
     2419                $screen_reader_text = __( 'Posts navigation' );
     2420        }
     2421
     2422        $template = '
     2423        <nav class="navigation %1$s" role="navigation">
     2424                <h1 class="screen-reader-text">%2$s</h1>
     2425                <div class="nav-links">%3$s</div>
     2426        </nav>';
     2427
     2428        return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links );
     2429}
     2430
     2431/**
    21912432 * Retrieve comments page number link.
    21922433 *
    21932434 * @since 2.7.0