The get_comments_pagination_arrow() WordPress PHP function is a helper function that returns the proper pagination arrow HTML for CommentsPaginationNext and CommentsPaginationPrevious blocks based on the provided paginationArrow from CommentsPagination context.
Usage
get_comments_pagination_arrow($block, $pagination_type);
Parameters
$block
(WP_Block): Required parameter representing the block instance.$pagination_type
(string): Optional parameter specifying the type of arrow to be rendered. Accepts ‘next’ or ‘previous’. Default value is ‘next’.
More information
See WordPress Developer Resources: get_comments_pagination_arrow()
Examples
Displaying the next arrow for comments pagination
In this example, we’ll display the next arrow for comments pagination using the get_comments_pagination_arrow() function.
// Fetching the block instance. $block = ...; // Calling the function with the 'next' arrow type. $next_arrow = get_comments_pagination_arrow($block, 'next'); // Displaying the next arrow. echo $next_arrow;
Displaying the previous arrow for comments pagination
In this example, we’ll display the previous arrow for comments pagination using the get_comments_pagination_arrow() function.
// Fetching the block instance. $block = ...; // Calling the function with the 'previous' arrow type. $previous_arrow = get_comments_pagination_arrow($block, 'previous'); // Displaying the previous arrow. echo $previous_arrow;
Customizing comments pagination with arrows
In this example, we’ll customize comments pagination by adding the next and previous arrows.
// Fetching the block instance. $block = ...; // Fetching the next arrow. $next_arrow = get_comments_pagination_arrow($block, 'next'); // Fetching the previous arrow. $previous_arrow = get_comments_pagination_arrow($block, 'previous'); // Displaying the customized comments pagination. echo $previous_arrow . ' ' . $next_arrow;
Conditionally displaying the next arrow for comments pagination
In this example, we’ll conditionally display the next arrow for comments pagination if there are more comments.
// Fetching the block instance. $block = ...; // Checking if there are more comments. if (get_next_comments_link()) { // Fetching and displaying the next arrow. echo get_comments_pagination_arrow($block, 'next'); }
Conditionally displaying the previous arrow for comments pagination
In this example, we’ll conditionally display the previous arrow for comments pagination if there are previous comments.
// Fetching the block instance. $block = ...; // Checking if there are previous comments. if (get_previous_comments_link()) { // Fetching and displaying the previous arrow. echo get_comments_pagination_arrow($block, 'previous'); }