WordPress.org

Make WordPress Core

Ticket #29808: 29808.diff

File 29808.diff, 4.4 KB (added by obenland, 5 years ago)
  • src/wp-includes/link-template.php

     
    21862186}
    21872187
    21882188/**
     2189 * Return navigation to next/previous post when applicable.
     2190 *
     2191 * @since 4.1.0
     2192 * @uses wp_parse_args()
     2193 * @uses get_previous_post_link()
     2194 * @uses get_next_post_link()
     2195 *
     2196 * @param array $args Optional.
     2197 * @return string
     2198 */
     2199function get_post_navigation( $args = array() ) {
     2200        $args = wp_parse_args( $args, array(
     2201                'prev_text' => _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link' ),
     2202                'next_text' => _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link' ),
     2203        ) );
     2204
     2205        $navigation = '';
     2206        $previous   = get_previous_post_link( '<div class="nav-previous">%link</div>', $args['prev_text'] );
     2207        $next       = get_next_post_link( '<div class="nav-next">%link</div>', $args['next_text'] );
     2208
     2209        // Don't print empty markup if there's nowhere to navigate.
     2210        if ( $next || $previous ) {
     2211                $navigation = _navigation_markup( $next . $previous, 'post-navigation', __( 'Post navigation' ) );
     2212        }
     2213
     2214        return $navigation;
     2215}
     2216
     2217/**
     2218 * Display navigation to next/previous post when applicable.
     2219 *
     2220 * @since 4.1.0
     2221 * @uses get_post_navigation()
     2222 */
     2223function the_post_navigation( $args = array() ) {
     2224        echo get_post_navigation( $args );
     2225}
     2226
     2227/**
     2228 * Return navigation to next/previous set of posts when applicable.
     2229 *
     2230 * @since 4.1.0
     2231 * @uses get_next_posts_link()
     2232 * @uses get_previous_posts_link()
     2233 *
     2234 * @global WP_Query $wp_query WordPress Query object.
     2235 * @param array $args Optional.
     2236 * @return string
     2237 */
     2238function get_paging_navigation( $args = array() ) {
     2239        $navigation = '';
     2240
     2241        // Don't print empty markup if there's only one page.
     2242        if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
     2243                return $navigation;
     2244        }
     2245
     2246        $args = wp_parse_args( $args, array(
     2247                'prev_text' => __( '<span class="meta-nav">&larr;</span> Older posts' ),
     2248                'next_text' => __( 'Newer posts <span class="meta-nav">&rarr;</span>' ),
     2249        ) );
     2250
     2251        $next_link = get_next_posts_link( $args['prev_text'] );
     2252        $prev_link = get_previous_posts_link( $args['next_text'] );
     2253
     2254        if ( $next_link ) {
     2255                $navigation .= '<div class="nav-previous">' . $next_link . '</div>';
     2256        }
     2257
     2258        if ( $prev_link ) {
     2259                $navigation .= '<div class="nav-next">' . $prev_link . '</div>';
     2260        }
     2261
     2262        return _navigation_markup( $navigation );
     2263}
     2264
     2265/**
     2266 * Display navigation to next/previous set of posts when applicable.
     2267 *
     2268 * @since 4.1.0
     2269 * @uses get_paging_navigation()
     2270 *
     2271 * @param array $args Optional.
     2272 */
     2273function the_paging_navigation( $args = array() ) {
     2274        echo get_paging_navigation( $args );
     2275}
     2276
     2277/**
     2278 * Return a paginated navigation to next/previous set of posts,
     2279 * when applicable.
     2280 *
     2281 * @since 4.1.0
     2282 * @uses wp_parse_args()
     2283 * @uses paginate_links()
     2284 *
     2285 * @param array $args Optional.
     2286 * @return string
     2287 */
     2288function get_pagination( $args = array() ) {
     2289        $navigation = '';
     2290
     2291        // Don't print empty markup if there's only one page.
     2292        if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
     2293                return $navigation;
     2294        }
     2295
     2296        $args = wp_parse_args( $args, array(
     2297                'mid_size'  => 1,
     2298                'prev_text' => __( '&larr; Previous' ),
     2299                'next_text' => __( 'Next &rarr;' ),
     2300        ) );
     2301
     2302        // Set up paginated links.
     2303        $links = paginate_links( $args );
     2304
     2305        if ( $links ) {
     2306                $navigation = _navigation_markup( $links, 'pagination' );
     2307        }
     2308
     2309        return $navigation;
     2310}
     2311
     2312/**
     2313 * Display a paginated navigation to next/previous set of posts,
     2314 * when applicable.
     2315 *
     2316 * @since 4.1.0
     2317 * @uses get_pagination()
     2318 *
     2319 * @param array $args Optional.
     2320 */
     2321function the_pagination( $args = array() ) {
     2322        echo get_pagination( $args );
     2323}
     2324
     2325/**
     2326 * Wraps passed links in navigational markup.
     2327 *
     2328 * @since 4.1.0
     2329 * @access private
     2330 *
     2331 * @param string $links
     2332 * @param string $class Optional.
     2333 * @param string $screen_reader_text Optional.
     2334 * @return string
     2335 */
     2336function _navigation_markup( $links, $class = 'paging-navigation', $screen_reader_text = '' ) {
     2337        if ( empty( $screen_reader_text ) ) {
     2338                $screen_reader_text = __( 'Posts navigation' );
     2339        }
     2340
     2341        $template = '<nav class="navigation %1$s" role="navigation">
     2342                                        <h1 class="screen-reader-text">%2$s</h1>
     2343                                        <div class="nav-links">%3$s</div>
     2344                                </nav>';
     2345
     2346        return sprintf( $template, $class, esc_html( $screen_reader_text ), $links );
     2347}
     2348
     2349/**
    21892350 * Retrieve comments page number link.
    21902351 *
    21912352 * @since 2.7.0