diff --git a/src/classes/theme-helper/class-tainacan-theme-helper.php b/src/classes/theme-helper/class-tainacan-theme-helper.php index 7e1455a67..1b28fe14b 100644 --- a/src/classes/theme-helper/class-tainacan-theme-helper.php +++ b/src/classes/theme-helper/class-tainacan-theme-helper.php @@ -1014,23 +1014,24 @@ class Theme_Helper { $carousel_div = $this->get_tainacan_items_carousel($carousel_args); } - - $output .= '
-
' . - $collection_heading . - $metadata_label . - $carousel_div . - '
-
- - ' . __('View all related items', 'tainacan') . ' - + if ( $related_group['total_items'] > 1 ) { + $output .= '
+
' . + $collection_heading . + $metadata_label . + $carousel_div . + ' +
- -
-
'; +
'; + } } } diff --git a/src/classes/theme-helper/template-tags.php b/src/classes/theme-helper/template-tags.php index ea55709fc..088e79bd1 100644 --- a/src/classes/theme-helper/template-tags.php +++ b/src/classes/theme-helper/template-tags.php @@ -1042,4 +1042,26 @@ function tainacan_the_items_carousel($args = []) { */ function tainacan_the_related_items_carousel($args = []) { echo \Tainacan\Theme_Helper::get_instance()->get_tainacan_related_items_carousel($args); +} + +/** + * Checks if the current item has or not related items + */ +function tainacan_has_related_items($item_id = false) { + // Gets the current Item + $item = $item_id ? \Tainacan\Theme_Helper::get_instance()->tainacan_get_item($item_id) : \Tainacan\Theme_Helper::get_instance()->tainacan_get_item(); + if (!$item) + return; + + // Then fetches related ones + $related_items = $item->get_related_items(); + if ( !$related_items || !is_array($related_items) || !count($related_items) ) + return false; + + // If we have at least one total_items, there are related items + foreach($related_items as $related_group) { + if ( isset($related_group['total_items']) && (int)$related_group['total_items'] > 0 ) + return true; + } + return false; } \ No newline at end of file diff --git a/src/views/gutenberg-blocks/tainacan-items/carousel-items-list/carousel-items-list-theme.js b/src/views/gutenberg-blocks/tainacan-items/carousel-items-list/carousel-items-list-theme.js index c00e932c0..0dccce54f 100644 --- a/src/views/gutenberg-blocks/tainacan-items/carousel-items-list/carousel-items-list-theme.js +++ b/src/views/gutenberg-blocks/tainacan-items/carousel-items-list/carousel-items-list-theme.js @@ -90,8 +90,6 @@ document.addEventListener("DOMContentLoaded", () => { this.collectionTextColor = this.$el.attributes['collection-text-color'] != undefined ? this.$el.attributes['collection-text-color'].value : undefined; this.tainacanApiRoot = this.$el.attributes['tainacan-api-root'] != undefined ? this.$el.attributes['tainacan-api-root'].value : undefined; this.tainacanBaseUrl = this.$el.attributes['tainacan-base-url'] != undefined ? this.$el.attributes['tainacan-base-url'].value : undefined; - - console.log(this.$el.attributes['hide-title'].value); }, methods: { __(text, domain) {