Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/block-library/src/tag-cloud/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"description": "A cloud of your most used tags.",
"textdomain": "default",
"attributes": {
"numberOfTags": {
"type": "number",
"default": 45,
"minimum": 1,
"maximum": 100
},
"taxonomy": {
"type": "string",
"default": "post_tag"
Expand Down
33 changes: 31 additions & 2 deletions packages/block-library/src/tag-cloud/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,34 @@ import { map, filter } from 'lodash';
/**
* WordPress dependencies
*/
import { PanelBody, ToggleControl, SelectControl } from '@wordpress/components';
import {
PanelBody,
ToggleControl,
SelectControl,
RangeControl,
} from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import ServerSideRender from '@wordpress/server-side-render';
import { store as coreStore } from '@wordpress/core-data';

/**
* Minimum number of tags a user can show using this block.
*
* @type {number}
*/
const MIN_TAGS = 1;

/**
* Maximum number of tags a user can show using this block.
*
* @type {number}
*/
const MAX_TAGS = 100;

function TagCloudEdit( { attributes, setAttributes, taxonomies } ) {
const { taxonomy, showTagCounts } = attributes;
const { taxonomy, showTagCounts, numberOfTags } = attributes;

const getTaxonomyOptions = () => {
const selectOption = {
Expand Down Expand Up @@ -53,6 +72,16 @@ function TagCloudEdit( { attributes, setAttributes, taxonomies } ) {
setAttributes( { showTagCounts: ! showTagCounts } )
}
/>
<RangeControl
label={ __( 'Number of tags' ) }
value={ numberOfTags }
onChange={ ( value ) =>
setAttributes( { numberOfTags: value } )
}
min={ MIN_TAGS }
max={ MAX_TAGS }
required
/>
</PanelBody>
</InspectorControls>
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/tag-cloud/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function render_block_core_tag_cloud( $attributes ) {
'echo' => false,
'taxonomy' => $attributes['taxonomy'],
'show_count' => $attributes['showTagCounts'],
'number' => $attributes['numberOfTags'],
);
$tag_cloud = wp_tag_cloud( $args );

Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/fixtures/blocks/core__tag-cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/tag-cloud",
"isValid": true,
"attributes": {
"numberOfTags": 45,
"taxonomy": "category",
"showTagCounts": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "core/tag-cloud",
"isValid": true,
"attributes": {
"numberOfTags": 45,
"taxonomy": "category",
"showTagCounts": true
},
Expand Down