diff --git a/includes/class-newspack-blocks-api.php b/includes/class-newspack-blocks-api.php
index d3656013a..304eda2f9 100644
--- a/includes/class-newspack-blocks-api.php
+++ b/includes/class-newspack-blocks-api.php
@@ -157,6 +157,17 @@ public static function newspack_blocks_sponsor_info( $object_info ) {
return false;
}
+ /**
+ * Get tag labels for the REST API.
+ *
+ * @param array $object_info The object info.
+ * @return array|bool Tag labels, or false if none.
+ */
+ public static function newspack_blocks_get_tag_labels( $object_info ) {
+ $tag_labels = Newspack_Blocks::get_tag_labels( $object_info['id'] );
+ return ! empty( $tag_labels ) ? array_values( $tag_labels ) : false;
+ }
+
/**
* Pass whether there is a custom excerpt to the editor.
*
@@ -269,6 +280,7 @@ public static function posts_endpoint( $request ) {
'newspack_post_sponsors' => self::newspack_blocks_sponsor_info( $data ),
'newspack_sponsors_show_author' => Newspack_Blocks::newspack_display_sponsors_and_authors( $sponsors ),
'newspack_sponsors_show_categories' => Newspack_Blocks::newspack_display_sponsors_and_categories( $sponsors ),
+ 'newspack_tag_labels' => self::newspack_blocks_get_tag_labels( $data ),
'newspack_post_avatars' => \newspack_blocks_format_avatars( $author_info ),
'newspack_post_byline' => \newspack_blocks_format_byline( $author_info ),
'post_status' => $post->post_status,
diff --git a/includes/class-newspack-blocks.php b/includes/class-newspack-blocks.php
index 8d3ffc113..49de655b5 100644
--- a/includes/class-newspack-blocks.php
+++ b/includes/class-newspack-blocks.php
@@ -1096,6 +1096,35 @@ public static function newspack_display_sponsors_and_categories( $sponsors ) {
return false;
}
+ /**
+ * Support for Tag Labels.
+ *
+ * @param int|WP_Post|null $post Post to retrieve tag labels for.
+ *
+ * @return array|null Tag labels, if any, for this post.
+ */
+ public static function get_tag_labels( $post = null ) {
+ if ( class_exists( '\Newspack\Tag_Labels' ) && method_exists( '\Newspack\Tag_Labels', 'get_labels_for_post' ) ) {
+ return \Newspack\Tag_Labels::get_labels_for_post( $post );
+ }
+
+ return null;
+ }
+
+ /**
+ * Outputs HTML for given tag labels.
+ *
+ * @param array|null $labels Labels to display.
+ * @param bool $links Whether to include links to tag archives.
+ *
+ * @return void
+ */
+ public static function display_tag_labels( $labels = null, $links = true ) {
+ if ( class_exists( '\Newspack\Tag_Labels' ) && method_exists( '\Newspack\Tag_Labels', 'display' ) ) {
+ \Newspack\Tag_Labels::display( $labels, $links, 'div' );
+ }
+ }
+
/**
* Closure for excerpt filtering that can be added and removed.
*
diff --git a/src/blocks/homepage-articles/block.json b/src/blocks/homepage-articles/block.json
index 7d50ccc48..69ec5a10b 100644
--- a/src/blocks/homepage-articles/block.json
+++ b/src/blocks/homepage-articles/block.json
@@ -84,6 +84,10 @@
"type": "boolean",
"default": false
},
+ "showTagLabels": {
+ "type": "boolean",
+ "default": true
+ },
"postLayout": {
"type": "string",
"default": "list"
diff --git a/src/blocks/homepage-articles/edit.tsx b/src/blocks/homepage-articles/edit.tsx
index 45498a22f..2767f721b 100644
--- a/src/blocks/homepage-articles/edit.tsx
+++ b/src/blocks/homepage-articles/edit.tsx
@@ -66,6 +66,7 @@ class Edit extends Component< HomepageArticlesProps > {
showAvatar,
showDate,
showCategory,
+ showTagLabels,
sectionHeader,
} = attributes;
@@ -112,6 +113,21 @@ class Edit extends Component< HomepageArticlesProps > {