-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query pagination with InnerBlocks (#28125)
* Add query pagination blocks * create fixtures * fix css var name * add new icons * use allowedFormats instead of formattingControls
- Loading branch information
1 parent
e40a88c
commit 1c59a2c
Showing
51 changed files
with
856 additions
and
186 deletions.
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.