/**
* The template for displaying archive pages
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package asallweb
*/
get_header();
// Берём настройки превью и сетки из ACF
$post_type = get_post_type();
$show_categories = false;
$terms = [];
// Проверяем, являемся ли мы архивом типа записей (не конкретной категории)
if ( is_post_type_archive() ) {
$taxonomies = get_object_taxonomies( $post_type, 'objects' );
foreach ( $taxonomies as $tax_name => $tax_obj ) {
// Игнорируем стандартные и технические таксономии (особенно Polylang)
if ( $tax_obj->public && !in_array($tax_name, ['post_tag', 'category', 'post_format', 'language', 'post_translations', 'term_translations', 'term_language', 'polylang_mo']) ) {
$found_terms = get_terms( array(
'taxonomy' => $tax_name,
'hide_empty' => false,
'parent' => 0,
) );
if ( !empty($found_terms) && !is_wp_error($found_terms) ) {
$terms = $found_terms;
$show_categories = true;
break;
}
}
}
}
// Берём настройки превью и сетки из ACF
// Если показываем категории, берем настройки таксономии, иначе - типа поста
$settings_source = ($show_categories && !empty($terms)) ? $terms[0]->taxonomy : $post_type;
$preview_settings = get_preview_settings_by_post_type($settings_source);
$grid_class = !empty($preview_settings['grid']) ? $preview_settings['grid'] : 'postsGridV1';
$preview_template = !empty($preview_settings['template']) ? $preview_settings['template'] : 'preview-v1';
?>
if (function_exists('getBreadCrumb')): ?>
endif; ?>
if ( have_posts() ) : ?>
endif; ?>
if ( $show_categories ) : ?>
$item_number = 0;
foreach ( $terms as $term ) :
$term_link = get_term_link($term);
$term_image = get_field('taxonomy_image', 'term_' . $term->term_id);
$thumbnail_url = !empty($term_image) ? $term_image : get_placeholder_image();
get_template_part(
'template-parts/template-previews/content',
$preview_template,
array(
'permalink' => is_wp_error($term_link) ? '' : $term_link,
'title' => $term->name,
'thumbnail_url' => $thumbnail_url,
'post_id' => 'term_' . $term->term_id,
'excerpt' => $term->description,
'description' => get_field('subtitle', 'term_' . $term->term_id),
'post_number' => $item_number,
'itemClass' => 'hasAnimation hidden',
'data_attrs' => 'data-animate="animate__fadeInUp" data-item-index="' . $item_number . '" data-delay-base="0.2"',
)
);
$item_number++;
endforeach;
?>
elseif ( have_posts() ) : ?>
$post_number = 0;
/* Start the Loop */
while ( have_posts() ) :
the_post();
get_template_part(
'template-parts/template-previews/content',
$preview_template,
[
'post_number' => $post_number,
'itemClass' => 'hasAnimation hidden',
'data_attrs' => 'data-animate="animate__fadeInUp" data-item-index="' . $post_number . '" data-delay-base="0.2"',
]
);
$post_number ++;
endwhile;
?>
the_posts_pagination(array(
'prev_text' => '
' . pll__('Previous') . '',
'next_text' => '
' . pll__('Next') . '',
));
?>
else: ?>
get_template_part( 'template-parts/content', 'none' ); ?>
endif; ?>
$term = get_queried_object();
$category_description = null;
if ( $term instanceof WP_Term ) {
$category_description = get_field('wysiwyg_description', 'term_' . $term->term_id);
}
if($category_description):?>
endif; ?>
get_footer();