-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Query pagination with InnerBlocks #28125
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Utility functions used for handling Query block and blocks | ||
* that | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Helper function that constructs a WP_Query args object from | ||
* a `Query` block properties. | ||
* | ||
* It's used in QueryLoop, QueryPaginationNumbers and QueryPaginationNext blocks. | ||
* | ||
* @param WP_Block $block Block instance. | ||
* @param int $page Curren query's page. | ||
* | ||
* @return object Returns the constructed WP_Query object. | ||
*/ | ||
function construct_wp_query_args( $block, $page ) { | ||
$query = array( | ||
'post_type' => 'post', | ||
'order' => 'DESC', | ||
'orderby' => 'date', | ||
'post__not_in' => array(), | ||
); | ||
|
||
if ( isset( $block->context['query'] ) ) { | ||
if ( isset( $block->context['query']['postType'] ) ) { | ||
$query['post_type'] = $block->context['query']['postType']; | ||
} | ||
if ( isset( $block->context['query']['sticky'] ) && ! empty( $block->context['query']['sticky'] ) ) { | ||
$sticky = get_option( 'sticky_posts' ); | ||
if ( 'only' === $block->context['query']['sticky'] ) { | ||
$query['post__in'] = $sticky; | ||
} else { | ||
$query['post__not_in'] = array_merge( $query['post__not_in'], $sticky ); | ||
} | ||
} | ||
if ( isset( $block->context['query']['exclude'] ) ) { | ||
$query['post__not_in'] = array_merge( $query['post__not_in'], $block->context['query']['exclude'] ); | ||
} | ||
if ( isset( $block->context['query']['perPage'] ) ) { | ||
$query['offset'] = ( $block->context['query']['perPage'] * ( $page - 1 ) ) + $block->context['query']['offset']; | ||
$query['posts_per_page'] = $block->context['query']['perPage']; | ||
} | ||
if ( isset( $block->context['query']['categoryIds'] ) ) { | ||
$query['category__in'] = $block->context['query']['categoryIds']; | ||
} | ||
if ( isset( $block->context['query']['tagIds'] ) ) { | ||
$query['tag__in'] = $block->context['query']['tagIds']; | ||
} | ||
if ( isset( $block->context['query']['order'] ) ) { | ||
$query['order'] = strtoupper( $block->context['query']['order'] ); | ||
} | ||
if ( isset( $block->context['query']['orderBy'] ) ) { | ||
$query['orderby'] = $block->context['query']['orderBy']; | ||
} | ||
if ( isset( $block->context['query']['author'] ) ) { | ||
$query['author'] = $block->context['query']['author']; | ||
} | ||
if ( isset( $block->context['query']['search'] ) ) { | ||
$query['s'] = $block->context['query']['search']; | ||
} | ||
} | ||
return $query; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/block-library/src/query-pagination-next/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"apiVersion": 2, | ||
"name": "core/query-pagination-next", | ||
"category": "design", | ||
"attributes": { | ||
"label": { | ||
"type": "string" | ||
} | ||
}, | ||
"usesContext": [ | ||
"queryId", | ||
"query" | ||
], | ||
"supports": { | ||
"reusable": false, | ||
"html": false, | ||
"color": { | ||
"gradients": true, | ||
"link": true | ||
}, | ||
"fontSize": true, | ||
"lineHeight": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useBlockProps, RichText } from '@wordpress/block-editor'; | ||
|
||
export default function QueryPaginationNextEdit( { | ||
attributes: { label }, | ||
setAttributes, | ||
} ) { | ||
const placeholder = __( 'Next Page' ); | ||
return ( | ||
<> | ||
<div { ...useBlockProps() }> | ||
{ | ||
<RichText | ||
tagName="a" | ||
aria-label={ __( 'Next page link' ) } | ||
placeholder={ placeholder } | ||
value={ label } | ||
allowedFormats={ [ 'core/bold', 'core/italic' ] } | ||
onChange={ ( newLabel ) => | ||
setAttributes( { label: newLabel } ) | ||
} | ||
/> | ||
} | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { _x, __ } from '@wordpress/i18n'; | ||
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 = { | ||
title: _x( 'Query Pagination Next', 'block title' ), | ||
description: __( 'Displays the next posts page link.' ), | ||
icon, | ||
edit, | ||
parent: [ 'core/query-pagination' ], | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this div also output in the frontend? if not, we should remove it and use the RichText as the wrapper (see Paragraph for instance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Maybe it's not possible because "a" is inline by default though). @ellatrix do you know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not. I'm not sure about this though:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible, we just need to update the display property to
inline-block
for example.