-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Block Library: Add the Comments Pagination Next block #36562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d21fb9f
8f56293
8b659ab
59bfce9
969fe74
c57ad77
265e8d8
fd078b9
6ea4a87
ce731b8
3e310f3
5ef8519
60a2e71
db2e960
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "apiVersion": 2, | ||
| "name": "core/comments-pagination-next", | ||
| "title": "Next Page", | ||
| "category": "theme", | ||
| "parent": [ "core/comments-pagination" ], | ||
| "description": "Displays the next comments page link.", | ||
| "textdomain": "default", | ||
| "attributes": { | ||
| "label": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "usesContext": [ "postId", "comments/perPage", "paginationArrow" ], | ||
| "supports": { | ||
| "reusable": false, | ||
| "html": false, | ||
| "color": { | ||
| "gradients": true, | ||
| "text": false | ||
| }, | ||
| "typography": { | ||
| "fontSize": true, | ||
| "lineHeight": true, | ||
| "__experimentalFontStyle": true, | ||
| "__experimentalFontWeight": true, | ||
| "__experimentalLetterSpacing": true, | ||
| "__experimentalTextTransform": true, | ||
| "__experimentalDefaultControls": { | ||
| "fontSize": true | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { useBlockProps, PlainText } from '@wordpress/block-editor'; | ||
|
|
||
| const arrowMap = { | ||
| none: '', | ||
| arrow: '→', | ||
| chevron: '»', | ||
| }; | ||
|
|
||
| export default function CommentsPaginationNextEdit( { | ||
| attributes: { label }, | ||
| setAttributes, | ||
| context: { paginationArrow }, | ||
| } ) { | ||
| const displayArrow = arrowMap[ paginationArrow ]; | ||
| return ( | ||
| <a | ||
| href="#comments-pagination-next-pseudo-link" | ||
| onClick={ ( event ) => event.preventDefault() } | ||
| { ...useBlockProps() } | ||
| > | ||
| <PlainText | ||
| __experimentalVersion={ 2 } | ||
| tagName="span" | ||
| aria-label={ __( 'Next comments page link' ) } | ||
| placeholder={ __( 'Next Comments' ) } | ||
| value={ label } | ||
| onChange={ ( newLabel ) => | ||
| setAttributes( { label: newLabel } ) | ||
| } | ||
| /> | ||
| { displayArrow && ( | ||
| <span | ||
| className={ `wp-block-query-pagination-next-arrow is-arrow-${ paginationArrow }` } | ||
| > | ||
| { displayArrow } | ||
| </span> | ||
| ) } | ||
| </a> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { queryPaginationNext as icon } from '@wordpress/icons'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import metadata from './block.json'; | ||
| import edit from './edit'; | ||
|
|
||
| const { name } = metadata; | ||
| export { metadata, name }; | ||
|
|
||
| export const settings = { | ||
| icon, | ||
| edit, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?php | ||
| /** | ||
| * Server-side rendering of the `core/comments-pagination-next` block. | ||
| * | ||
| * @package WordPress | ||
| */ | ||
|
|
||
| /** | ||
| * Renders the `core/comments-pagination-next` block on the server. | ||
| * | ||
| * @param array $attributes Block attributes. | ||
| * @param string $content Block default content. | ||
| * @param WP_Block $block Block instance. | ||
| * | ||
| * @return string Returns the next comments link for the query pagination. | ||
| */ | ||
| function render_block_core_comments_pagination_next( $attributes, $content, $block ) { | ||
| $per_page = ! empty( $block->context['comments/perPage'] ) ? (int) $block->context['comments/perPage'] : 0; | ||
| if ( 0 === $per_page && get_option( 'page_comments' ) ) { | ||
| $per_page = (int) get_query_var( 'comments_per_page' ); | ||
| if ( 0 === $per_page ) { | ||
| $per_page = (int) get_option( 'comments_per_page' ); | ||
| } | ||
| } | ||
| $comments_number = (int) get_comments_number(); | ||
| $max_page = isset( $per_page ) ? (int) floor( $comments_number / $per_page ) : 0; | ||
| $default_label = __( 'Next Comments' ); | ||
| $label = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label; | ||
| $pagination_arrow = get_query_pagination_arrow( $block, true ); | ||
|
|
||
| $filter_link_attributes = function() { | ||
| return get_block_wrapper_attributes(); | ||
| }; | ||
| add_filter( 'next_comments_link_attributes', $filter_link_attributes ); | ||
|
|
||
| if ( $pagination_arrow ) { | ||
| $label .= $pagination_arrow; | ||
| } | ||
|
|
||
| $next_comments_link = get_next_comments_link( $label, $max_page ); | ||
|
||
|
|
||
| remove_filter( 'next_posts_link_attributes', $filter_link_attributes ); | ||
|
|
||
| if ( ! isset( $next_comments_link ) ) { | ||
| return ''; | ||
| } | ||
| return $next_comments_link; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Registers the `core/comments-pagination-next` block on the server. | ||
| */ | ||
| function register_block_core_comments_pagination_next() { | ||
| register_block_type_from_metadata( | ||
| __DIR__ . '/comments-pagination-next', | ||
| array( | ||
| 'render_callback' => 'render_block_core_comments_pagination_next', | ||
| ) | ||
| ); | ||
| } | ||
| add_action( 'init', 'register_block_core_comments_pagination_next' ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <!-- wp:comments-pagination-next {"label":"Next Comments","style":{"typography":{"textTransform":"lowercase"}},"fontSize":"medium"} /--> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [ | ||
| { | ||
| "clientId": "_clientId_0", | ||
| "name": "core/comments-pagination-next", | ||
| "isValid": true, | ||
| "attributes": { | ||
| "label": "Next Comments", | ||
| "fontSize": "medium", | ||
| "style": { | ||
| "typography": { | ||
| "textTransform": "lowercase" | ||
| } | ||
| } | ||
| }, | ||
| "innerBlocks": [], | ||
| "originalContent": "" | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [ | ||
| { | ||
| "blockName": "core/comments-pagination-next", | ||
| "attrs": { | ||
| "label": "Next Comments", | ||
| "style": { | ||
| "typography": { | ||
| "textTransform": "lowercase" | ||
| } | ||
| }, | ||
| "fontSize": "medium" | ||
| }, | ||
| "innerBlocks": [], | ||
| "innerHTML": "", | ||
| "innerContent": [] | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <!-- wp:comments-pagination-next {"label":"Next Comments","fontSize":"medium","style":{"typography":{"textTransform":"lowercase"}}} /--> |


Uh oh!
There was an error while loading. Please reload this page.