| | 2702 | * Return navigation to next/previous set of comments when applicable. |
| | 2703 | * |
| | 2704 | * @since 4.4.0 |
| | 2705 | * |
| | 2706 | * @param array $args { |
| | 2707 | * Optional. Default comments navigation arguments. |
| | 2708 | * |
| | 2709 | * @type string $prev_text Anchor text to display in the previous comments link. Default 'Older comments'. |
| | 2710 | * @type string $next_text Anchor text to display in the next comments link. Default 'Newer comments'. |
| | 2711 | * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. |
| | 2712 | * } |
| | 2713 | * @return string Markup for comments links. |
| | 2714 | */ |
| | 2715 | function get_the_comments_navigation( $args = array() ) { |
| | 2716 | $navigation = ''; |
| | 2717 | |
| | 2718 | // Are there comments to navigate through? |
| | 2719 | if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) { |
| | 2720 | $args = wp_parse_args( $args, array( |
| | 2721 | 'prev_text' => __( 'Older comments' ), |
| | 2722 | 'next_text' => __( 'Newer comments' ), |
| | 2723 | 'screen_reader_text' => __( 'Comments navigation' ), |
| | 2724 | ) ); |
| | 2725 | |
| | 2726 | $prev_link = get_previous_comments_link( $args['prev_text'] ); |
| | 2727 | $next_link = get_next_comments_link( $args['next_text'] ); |
| | 2728 | |
| | 2729 | if ( $prev_link ) { |
| | 2730 | $navigation .= '<div class="nav-previous">' . $prev_link . '</div>'; |
| | 2731 | } |
| | 2732 | |
| | 2733 | if ( $next_link ) { |
| | 2734 | $navigation .= '<div class="nav-next">' . $next_link . '</div>'; |
| | 2735 | } |
| | 2736 | |
| | 2737 | $navigation = _navigation_markup( $navigation, 'comment-navigation', $args['screen_reader_text'] ); |
| | 2738 | } |
| | 2739 | |
| | 2740 | return $navigation; |
| | 2741 | } |
| | 2742 | |
| | 2743 | /** |
| | 2744 | * Display navigation to next/previous set of comments when applicable. |
| | 2745 | * |
| | 2746 | * @since 4.4.0 |
| | 2747 | * |
| | 2748 | * @param array $args See {@see get_the_comments_navigation()} for available arguments. |
| | 2749 | */ |
| | 2750 | function the_comments_navigation( $args = array() ) { |
| | 2751 | echo get_the_comments_navigation( $args ); |
| | 2752 | } |
| | 2753 | |
| | 2754 | /** |
| | 2755 | * Return a paginated navigation to next/previous set of comments, |
| | 2756 | * when applicable. |
| | 2757 | * |
| | 2758 | * @since 4.4.0 |
| | 2759 | * |
| | 2760 | * @see paginate_comments_links() |
| | 2761 | * |
| | 2762 | * @param array $args { |
| | 2763 | * Optional. Default pagination arguments. |
| | 2764 | * |
| | 2765 | * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. |
| | 2766 | * } |
| | 2767 | * @return string Markup for pagination links. |
| | 2768 | */ |
| | 2769 | function get_the_comments_pagination( $args = array() ) { |
| | 2770 | $navigation = ''; |
| | 2771 | $args = wp_parse_args( $args, array( |
| | 2772 | 'screen_reader_text' => __( 'Comments navigation' ), |
| | 2773 | ) ); |
| | 2774 | $args['echo'] = false; |
| | 2775 | |
| | 2776 | // Make sure we get plain links, so we get a string we can work with. |
| | 2777 | $args['type'] = 'plain'; |
| | 2778 | |
| | 2779 | $links = paginate_comments_links( $args ); |
| | 2780 | |
| | 2781 | if ( $links ) { |
| | 2782 | $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'] ); |
| | 2783 | } |
| | 2784 | |
| | 2785 | return $navigation; |
| | 2786 | } |
| | 2787 | |
| | 2788 | /** |
| | 2789 | * Display a paginated navigation to next/previous set of comments, |
| | 2790 | * when applicable. |
| | 2791 | * |
| | 2792 | * @since 4.4.0 |
| | 2793 | * |
| | 2794 | * @param array $args See {@see get_the_comments_pagination()} for available arguments. |
| | 2795 | */ |
| | 2796 | function the_comments_pagination( $args = array() ) { |
| | 2797 | echo get_the_comments_pagination( $args ); |
| | 2798 | } |
| | 2799 | |
| | 2800 | /** |