From f1df8dd97e40870a129855330bddcb702c867569 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 10 May 2022 16:12:33 -0300 Subject: [PATCH] Improves section metadata usage of filters. --- .../tainacan-item-single-metadata_new.php | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tainacan-blocksy/template-parts/tainacan-item-single-metadata_new.php b/tainacan-blocksy/template-parts/tainacan-item-single-metadata_new.php index ee1a277..c010517 100644 --- a/tainacan-blocksy/template-parts/tainacan-item-single-metadata_new.php +++ b/tainacan-blocksy/template-parts/tainacan-item-single-metadata_new.php @@ -1,6 +1,72 @@ screen->get_prefix(); + /** + * The new metadata sections function makes it a bit more complicated to add + * the thumbnail in the middle of the metadata. + * So we have some logic that is only needed if it is set. + * The following uses a filter to add it right above the first metadatum in the first section. + **/ + + if ( has_post_thumbnail() && (get_theme_mod($prefix . '_show_thumbnail', 'no') === 'yes') ) { + + // Gets collection so we can obtain firtst metadatum + $collection = tainacan_get_collection(); + + if ( !is_null($collection) ) { + + // Gets array of metadata order + $metadata_order = $collection->get_metadata_order(); + + if ( is_array($metadata_order) ) { + + $first_metadatum_id = -1; + + foreach( $metadata_order as $metadatum ) { + + // Checks if the metadata is enabled + if ( isset($metadatum['enabled']) && $metadatum['enabled'] && isset($metadatum['id']) ) { + $first_metadatum_id = $metadatum['id']; + + // IF we are not displaying the title here, we must look for the second metadata + if ( get_theme_mod($prefix . '_show_title_metadata', 'yes') === 'no' ) { + + $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); + $metadatum_object = $Tainacan_Metadata->fetch($first_metadatum_id); + $metadata_type_object = $metadatum_object->get_metadata_type_object(); + + if ( $metadata_type_object->get_related_mapped_prop() == 'title' ) { + continue; + } + } + + break; + } + } + + if ( is_numeric($first_metadatum_id) && $first_metadatum_id >= 0 ) { + + add_filter('tainacan-get-item-metadatum-as-html-before--id-' . $first_metadatum_id, function($before, $item_metadatum) { + + ob_start(); + ?> +
+ + +
+ true, 'before_title' => '

',