Skip to content

Commit

Permalink
Post terms: Add a CSS class to identify the taxonomy (#31832)
Browse files Browse the repository at this point in the history
* Post terms: Add a CSS class to identify the taxonomy

* Linting
  • Loading branch information
carolinan authored Jun 11, 2021
1 parent 63d6ea6 commit dcc2e36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/post-terms/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function PostTermsEdit( {
const blockProps = useBlockProps( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
[ `taxonomy-${ term }` ]: term,
} ),
} );

Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/post-terms/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
return '';
}

$align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}";
$classes = 'taxonomy-' . $attributes['term'];
if ( isset( $attributes['textAlign'] ) ) {
$classes .= ' has-text-align-' . $attributes['textAlign'];
}

$terms_links = '';
foreach ( $post_terms as $term ) {
Expand All @@ -37,7 +40,7 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
);
}
$terms_links = trim( $terms_links, ' | ' );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );

return sprintf(
'<div %1$s>%2$s</div>',
Expand Down

0 comments on commit dcc2e36

Please sign in to comment.