
آنجلا چامپانیا (Angela Ciampagna)
add_action(‘woocommerce_archive_description’, function() { if ( ! is_tax(‘perfumer’) ) return; $term = get_queried_object(); if ( ! $term || empty( $term->term_id )...
add_action(‘woocommerce_archive_description’, function() {
if ( ! is_tax(‘perfumer’) ) return;
$term = get_queried_object();
if ( ! $term || empty( $term->term_id ) ) return;
$field_id = $term->taxonomy . ‘_’ . $term->term_id;
$photo_id = get_field( ‘perfumer_photo’, $field_id );
$bio = get_field( ‘perfumer_biography’, $field_id );
$photo_url = $photo_id ? wp_get_attachment_image_url( (int) $photo_id, ‘full’ ) : ”;
$bio_short = wp_trim_words( wp_strip_all_tags( $bio ), 20, ‘…’ );
echo ‘<div class=”hamin-perfumer-box”>’;
echo ‘<h2>’ . esc_html( $term->name ) . ‘</h2>’;
if ( $photo_url ) {
echo ‘<img src=”‘ . esc_url( $photo_url ) . ‘” alt=”‘ . esc_attr( $term->name ) . ‘”>’;
}
echo ‘<p class=”hamin-perfumer-bio-short”>’ . esc_html( $bio_short ) . ‘</p>’;
echo ‘<div class=”hamin-perfumer-bio-full”>’ . wp_kses_post( $bio ) . ‘</div>’;
echo ‘<button type=”button” class=”hamin-perfumer-toggle”>بیشتر بخوانید</button>’;
echo ‘</div>’;
?>
<style>
.hamin-perfumer-bio-full {
max-height: 0;
opacity: 0;
overflow: hidden;
transition: max-height 0.4s ease, opacity 0.4s ease;
}
.hamin-perfumer-bio-full.hamin-open {
max-height: 1000px;
opacity: 1;
}
.hamin-perfumer-toggle {
cursor: pointer;
background: none;
border: none;
color: inherit;
text-decoration: underline;
padding: 0;
font: inherit;
}
</style>
<script>
document.addEventListener(‘DOMContentLoaded’, function() {
document.querySelectorAll(‘.hamin-perfumer-toggle’).forEach(function(btn) {
btn.addEventListener(‘click’, function() {
var box = btn.closest(‘.hamin-perfumer-box’);
var full = box.querySelector(‘.hamin-perfumer-bio-full’);
var short = box.querySelector(‘.hamin-perfumer-bio-short’);
full.classList.toggle(‘hamin-open’);
short.style.display = full.classList.contains(‘hamin-open’) ? ‘none’ : ‘block’;
btn.textContent = full.classList.contains(‘hamin-open’) ? ‘بستن’ : ‘بیشتر بخوانید’;
});
});
});
</script>
<?php
}, 5);
نمایش همه 2 نتیجه