Make WordPress Core

Ticket #39447: 39447.4.diff

File 39447.4.diff, 4.8 KB (added by Howdy_McGee, 4 years ago)

New $total argument for get_the_posts_pagination( $args )

  • link-template.php

     
    27182718 *                                      Default 'Posts navigation'.
    27192719 *     @type string $aria_label         ARIA label text for the nav element. Default 'Posts'.
    27202720 *     @type string $class              Custom class for the nav element. Default 'posts-navigation'.
     2721 *     @type int $max_num_pages         Maximum number of pages.
     2722 *                                      Default to global `$wp_query->max_num_pages`.
    27212723 * }
    27222724 * @return string Markup for posts links.
    27232725 */
    27242726function get_the_posts_navigation( $args = array() ) {
     2727        global $wp_query;
     2728
    27252729        $navigation = '';
    27262730
    2727         // Don't print empty markup if there's only one page.
    2728         if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
    2729                 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
    2730                 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
    2731                         $args['aria_label'] = $args['screen_reader_text'];
    2732                 }
     2731        // Make sure the nav element has an aria-label attribute, fallback to the screen reader text.
     2732        if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
     2733                $args['aria_label'] = $args['screen_reader_text'];
     2734        }
    27332735
    2734                 $args = wp_parse_args(
    2735                         $args,
    2736                         array(
    2737                                 'prev_text'          => __( 'Older posts' ),
    2738                                 'next_text'          => __( 'Newer posts' ),
    2739                                 'screen_reader_text' => __( 'Posts navigation' ),
    2740                                 'aria_label'         => __( 'Posts' ),
    2741                                 'class'              => 'posts-navigation',
    2742                         )
    2743                 );
     2736        $args = wp_parse_args(
     2737                $args,
     2738                array(
     2739                        'prev_text'          => __( 'Older posts' ),
     2740                        'next_text'          => __( 'Newer posts' ),
     2741                        'screen_reader_text' => __( 'Posts navigation' ),
     2742                        'aria_label'         => __( 'Posts' ),
     2743                        'class'              => 'posts-navigation',
     2744                        'max_num_pages'      => $wp_query->max_num_pages,
     2745                )
     2746        );
    27442747
     2748        // Don't print empty markup if there's only one page.
     2749        if ( $args['max_num_pages'] > 1 ) {
    27452750                $next_link = get_previous_posts_link( $args['next_text'] );
    2746                 $prev_link = get_next_posts_link( $args['prev_text'] );
     2751                $prev_link = get_next_posts_link( $args['prev_text'], $args['max_num_pages'] );
    27472752
    27482753                if ( $prev_link ) {
    27492754                        $navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
     
    27852790 *                                      Default 'Posts navigation'.
    27862791 *     @type string $aria_label         ARIA label text for the nav element. Default 'Posts'.
    27872792 *     @type string $class              Custom class for the nav element. Default 'pagination'.
     2793 *     @type int $total                 Total number of pages.
     2794 *                                      Default to global `$wp_query->max_num_pages`.
    27882795 * }
    27892796 * @return string Markup for pagination links.
    27902797 */
    27912798function get_the_posts_pagination( $args = array() ) {
     2799        global $wp_query;
     2800
    27922801        $navigation = '';
    27932802
    2794         // Don't print empty markup if there's only one page.
    2795         if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
    2796                 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
    2797                 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
    2798                         $args['aria_label'] = $args['screen_reader_text'];
    2799                 }
     2803        // Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
     2804        if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
     2805                $args['aria_label'] = $args['screen_reader_text'];
     2806        }
    28002807
    2801                 $args = wp_parse_args(
    2802                         $args,
    2803                         array(
    2804                                 'mid_size'           => 1,
    2805                                 'prev_text'          => _x( 'Previous', 'previous set of posts' ),
    2806                                 'next_text'          => _x( 'Next', 'next set of posts' ),
    2807                                 'screen_reader_text' => __( 'Posts navigation' ),
    2808                                 'aria_label'         => __( 'Posts' ),
    2809                                 'class'              => 'pagination',
    2810                         )
    2811                 );
     2808        $args = wp_parse_args(
     2809                $args,
     2810                array(
     2811                        'mid_size'           => 1,
     2812                        'prev_text'          => _x( 'Previous', 'previous set of posts' ),
     2813                        'next_text'          => _x( 'Next', 'next set of posts' ),
     2814                        'screen_reader_text' => __( 'Posts navigation' ),
     2815                        'aria_label'         => __( 'Posts' ),
     2816                        'class'              => 'pagination',
     2817                        'total'              => $wp_query->max_num_pages,
     2818                )
     2819        );
    28122820
    2813                 // Make sure we get a string back. Plain is the next best thing.
    2814                 if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
    2815                         $args['type'] = 'plain';
    2816                 }
     2821        // Make sure we get a string back. Plain is the next best thing.
     2822        if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
     2823                $args['type'] = 'plain';
     2824        }
    28172825
     2826        // Don't print empty markup if there's only one page.
     2827        if ( $args['total'] > 1 ) {
     2828
    28182829                // Set up paginated links.
    28192830                $links = paginate_links( $args );
    28202831