diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index dd49d156857249..dd28747d5f02ec 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -775,7 +775,7 @@ Display the query title. ([Source](https://github.com/WordPress/gutenberg/tree/t - **Name:** core/query-title - **Category:** theme - **Supports:** align (full, wide), color (background, gradients, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~ -- **Attributes:** level, levelOptions, showPrefix, showSearchTerm, textAlign, type +- **Attributes:** blogTitle, level, levelOptions, showPrefix, showSearchTerm, textAlign, type ## Quote diff --git a/packages/block-library/src/query-title/block.json b/packages/block-library/src/query-title/block.json index 5d5c9113bda084..5f539702bc4297 100644 --- a/packages/block-library/src/query-title/block.json +++ b/packages/block-library/src/query-title/block.json @@ -27,6 +27,10 @@ "showSearchTerm": { "type": "boolean", "default": true + }, + "blogTitle": { + "type": "string", + "default": "Blog" } }, "example": { diff --git a/packages/block-library/src/query-title/edit.js b/packages/block-library/src/query-title/edit.js index 21d23081837cdf..d459f5ac4efe40 100644 --- a/packages/block-library/src/query-title/edit.js +++ b/packages/block-library/src/query-title/edit.js @@ -22,7 +22,7 @@ import { __, _x, sprintf } from '@wordpress/i18n'; */ import { useArchiveLabel } from './use-archive-label'; -const SUPPORTED_TYPES = [ 'archive', 'search' ]; +const SUPPORTED_TYPES = [ 'archive', 'search', 'blog' ]; export default function QueryTitleEdit( { attributes: { @@ -32,10 +32,14 @@ export default function QueryTitleEdit( { textAlign, showPrefix, showSearchTerm, + blogTitle, }, setAttributes, } ) { const { archiveTypeLabel, archiveNameLabel } = useArchiveLabel(); + const currentTemplate = useSelect( ( select ) => { + return select( coreStore )?.getEditedPostType(); + } ); const TagName = `h${ level }`; const blockProps = useBlockProps( { @@ -44,7 +48,10 @@ export default function QueryTitleEdit( { } ), } ); - if ( ! SUPPORTED_TYPES.includes( type ) ) { + if ( + ! SUPPORTED_TYPES.includes( type ) && + ! [ 'index', 'home' ].includes( currentTemplate ) + ) { return (
{ __( 'Provided type is not supported.' ) } @@ -103,9 +110,7 @@ export default function QueryTitleEdit( { { title } ); - } - - if ( type === 'search' ) { + } else if ( type === 'search' ) { titleElement = ( <> @@ -130,6 +135,30 @@ export default function QueryTitleEdit( { ); + } else if ( + [ 'index', 'home' ].includes( currentTemplate ) || + type === 'blog' + ) { + titleElement = ( + <> + + + + setAttributes( { blogTitle: value } ) + } + /> + + + + { blogTitle || __( 'Blog' ) } + + + ); } return ( @@ -149,7 +178,13 @@ export default function QueryTitleEdit( { } } /> - { titleElement } + { titleElement || ( +
+ + { __( 'Unsupported template for Query Title block.' ) } + +
+ ) } ); } diff --git a/packages/block-library/src/query-title/index.php b/packages/block-library/src/query-title/index.php index 88a945535a22d9..2c7cf3f6de59d9 100644 --- a/packages/block-library/src/query-title/index.php +++ b/packages/block-library/src/query-title/index.php @@ -27,6 +27,11 @@ function render_block_core_query_title( $attributes ) { return ''; } $title = ''; + + if ( is_home() || is_front_page() ) { + $title = isset( $attributes['blogTitle'] ) ? $attributes['blogTitle'] : __( 'Blog' ); + } + if ( $is_archive ) { $show_prefix = isset( $attributes['showPrefix'] ) ? $attributes['showPrefix'] : true; if ( ! $show_prefix ) { diff --git a/test/integration/fixtures/blocks/core__query-title.json b/test/integration/fixtures/blocks/core__query-title.json index df90d4b0e6d4e4..2cb096c2dc935c 100644 --- a/test/integration/fixtures/blocks/core__query-title.json +++ b/test/integration/fixtures/blocks/core__query-title.json @@ -5,7 +5,8 @@ "attributes": { "level": 1, "showPrefix": true, - "showSearchTerm": true + "showSearchTerm": true, + "blogTitle": "Blog" }, "innerBlocks": [] }