Creates template function to check if there are related items.

This commit is contained in:
mateuswetah 2021-07-02 15:06:59 -03:00
parent 542baac6eb
commit db617b3f29
3 changed files with 38 additions and 17 deletions

View File

@ -1014,7 +1014,7 @@ class Theme_Helper {
$carousel_div = $this->get_tainacan_items_carousel($carousel_args);
}
if ( $related_group['total_items'] > 1 ) {
$output .= '<div class="wp-block-group">
<div class="wp-block-group__inner-container">' .
$collection_heading .
@ -1023,7 +1023,7 @@ class Theme_Helper {
'<div class="wp-block-buttons">
<div class="wp-block-button">
<a class="wp-block-button__link">
' . __('View all related items', 'tainacan') . '
' . sprintf( __('View all (%s) related items', 'tainacan'), $related_group['total_items'] ) . '
</a>
</div>
</div>
@ -1033,6 +1033,7 @@ class Theme_Helper {
</div>';
}
}
}
$output .= '</div>';

View File

@ -1043,3 +1043,25 @@ 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;
}

View File

@ -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) {