block_name ); $wrapper_styles = $this->get_wrapper_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}}', $wrapper_styles, $this->get_wrapper_css( $attributes, 'Tablet' ), $this->get_wrapper_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } ) ); $card_styles = $this->get_card_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-listing-item', $card_styles, $this->get_card_css( $attributes, 'Tablet' ), $this->get_card_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_card_css( $attributes, $device ); } ) ); $card_hover_styles = $this->get_card_hover_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-listing-item:hover', $card_hover_styles, $this->get_card_hover_css( $attributes, 'Tablet' ), $this->get_card_hover_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_card_hover_css( $attributes, $device ); } ) ); $card_padding_styles = $this->get_card_padding_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-listing-item_content', $card_padding_styles, $this->get_card_padding_css( $attributes, 'Tablet' ), $this->get_card_padding_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_card_padding_css( $attributes, $device ); } ) ); $taxonomy_title_styles = $this->get_taxonomy_title_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-title', $taxonomy_title_styles, $this->get_taxonomy_title_css( $attributes, 'Tablet' ), $this->get_taxonomy_title_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_taxonomy_title_css( $attributes, $device ); } ) ); $taxonomy_title_hover_styles = $this->get_taxonomy_hover_title_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-title:hover', $taxonomy_title_hover_styles, $this->get_taxonomy_hover_title_css( $attributes, 'Tablet' ), $this->get_taxonomy_hover_title_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_taxonomy_hover_title_css( $attributes, $device ); } ) ); // Icon style $icons_style = $this->get_icons( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-icon', $icons_style, $this->get_icons( $attributes, 'Tablet' ), $this->get_icons( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icons( $attributes, $device ); } ) ); // Icon style $icons_svg_style = $this->get_icons_svg( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-icon svg', $icons_svg_style, $this->get_icons_svg( $attributes, 'Tablet' ), $this->get_icons_svg( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icons_svg( $attributes, $device ); } ) ); // Icon style $icon_svg_path_style = $this->get_icon_svg_path( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-icon svg path', $icon_svg_path_style, $this->get_icon_svg_path( $attributes, 'Tablet' ), $this->get_icon_svg_path( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_svg_path( $attributes, $device ); } ) ); // Post Title Start $post_title_styles = $this->get_post_title_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-posts a', $post_title_styles, $this->get_post_title_css( $attributes, 'Tablet' ), $this->get_post_title_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_title_css( $attributes, $device ); } ) ); $post_hover_styles = $this->get_post_hover_title_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-posts a:hover', $post_hover_styles, $this->get_post_hover_title_css( $attributes, 'Tablet' ), $this->get_post_hover_title_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_hover_title_css( $attributes, $device ); } ) ); $post_active_styles = $this->get_post_active_title_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-posts a.active-post-link', $post_active_styles, $this->get_post_active_title_css( $attributes, 'Tablet' ), $this->get_post_active_title_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_active_title_css( $attributes, $device ); } ) ); // Post Title End $post_count_styles = $this->get_post_title_count_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-title__post-count', $post_count_styles, $this->get_post_title_count_css( $attributes, 'Tablet' ), $this->get_post_title_count_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_title_count_css( $attributes, $device ); } ) ); $post_count_hover_styles = $this->get_post_title_hover_count_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-title__post-count:hover', $post_count_hover_styles, $this->get_post_title_hover_count_css( $attributes, 'Tablet' ), $this->get_post_title_hover_count_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_title_hover_count_css( $attributes, $device ); } ) ); $button_styles = $this->get_button_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-reload-button', $button_styles, $this->get_button_css( $attributes, 'Tablet' ), $this->get_button_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_css( $attributes, $device ); } ) ); $button_hover_styles = $this->get_button_hover_css( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-reload-button:hover', $button_hover_styles, $this->get_button_hover_css( $attributes, 'Tablet' ), $this->get_button_hover_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_hover_css( $attributes, $device ); } ) ); // Icon Style $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-icon-wrap', Icon::get_wrapper_css( $attributes ), Icon::get_wrapper_css( $attributes, 'Tablet' ), Icon::get_wrapper_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon', Icon::get_element_image_css( $attributes ), Icon::get_element_image_css( $attributes, 'Tablet' ), Icon::get_element_image_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_css( $attributes, $device ); } ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover', Icon::get_element_image_hover_css( $attributes ), Icon::get_element_image_hover_css( $attributes, 'Tablet' ), Icon::get_element_image_hover_css( $attributes, 'Mobile' ), ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon', Icon::get_element_css( $attributes ), Icon::get_element_css( $attributes, 'Tablet' ), Icon::get_element_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_css( $attributes, $device ); } ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover', Icon::get_element_image_hover_css( $attributes ), Icon::get_element_image_hover_css( $attributes, 'Tablet' ), Icon::get_element_image_hover_css( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } ) ); // Layout grid if ( $attributes['taxonomyLayout'] === 'flex' ) { $main_wrapper_css = $this->get_card_wrapper( $attributes ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-taxonomy-listing_flex', $main_wrapper_css, $this->get_card_wrapper( $attributes, 'Tablet' ), $this->get_card_wrapper( $attributes, 'Mobile' ), $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_card_wrapper( $attributes, $device ); } ) ); } return $css_generator->generate_css(); } public function get_wrapper_css( $attributes, $device = '' ) { return isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : []; } public function get_taxonomy_title_css( $attributes, $device = '' ) { $css = []; // Color if ( ! empty( $attributes['taxonomyTitlecolor'] ) ) { $css['color'] = $attributes['taxonomyTitlecolor']; } // Background if ( ! empty( $attributes['taxonomyTitletBgColor'] ) ) { $css['background'] = $attributes['taxonomyTitletBgColor']; } // Justify content (alignment) if ( isset( $attributes['taxonomyTitlePosition'][ 'value' . $device ] ) ) { $css['justify-content'] = $attributes['taxonomyTitlePosition'][ 'value' . $device ]; } // Flex direction if ( isset( $attributes['taxonomyTitleDirection'][ 'value' . $device ] ) ) { $css['flex-direction'] = $attributes['taxonomyTitleDirection'][ 'value' . $device ]; } $typographyValueGlobal = ! empty( $attributes['taxonomyTitleTypographyGlobal'] ) ? $attributes['taxonomyTitleTypographyGlobal'] : []; return array_merge( Typography::get_css( $attributes['taxonomyTitleTypography'] ?? [], '', $device, $typographyValueGlobal ), Border::get_css( $attributes['taxonomyTitleBorder'] ?? [], '', $device ), Dimensions::get_css( $attributes['taxonomyTitlePadding'] ?? [], 'padding', $device ), $css ); } public function get_taxonomy_hover_title_css( $attributes, $device = '' ) { $css = []; $taxonomy_title_border = ! empty( $attributes['taxonomyTitleBorder'] ) ? Border::get_hover_css( $attributes['taxonomyTitleBorder'], '', $device ) : array(); return array_merge( $taxonomy_title_border ); } public function get_post_title_count_css( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['postCountColor'] ) ) { $css['color'] = $attributes['postCountColor']; } if ( ! empty( $attributes['postCountBgColor'] ) ) { $css['background'] = $attributes['postCountBgColor']; } if ( ! empty( $attributes['postCountWidth'] ) ) { $css['width'] = $attributes['postCountWidth'] . 'px'; } if ( ! empty( $attributes['postCountWidth'] ) ) { $css['height'] = $attributes['postCountWidth'] . 'px'; } $typographyValueGlobal = ! empty( $attributes['postCountTypographyGlobal'] ) ? $attributes['postCountTypographyGlobal'] : []; return array_merge( Border::get_css( $attributes['postCountBorder'] ?? [], '', $device ), Dimensions::get_css( $attributes['padding'] ?? [], 'padding', $device ), Typography::get_css( $attributes['postCountTypography'] ?? [], '', $device, $typographyValueGlobal ), $css ); } public function get_post_title_hover_count_css( $attributes, $device = '' ) { $post_count_hover_border_style = ! empty( $attributes['postCountBorder'] ) ? Border::get_hover_css( $attributes['postCountBorder'], '', $device ) : array(); return array_merge( $post_count_hover_border_style ); } public function get_card_css( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['cardBgColor'] ) ) { $css['background'] = $attributes['cardBgColor']; } return array_merge( Border::get_css( $attributes['cardBorder'] ?? [], '', $device ), BoxShadow::get_css( $attributes['cardBoxShadow'] ?? [], '', $device ), $css ); } public function get_card_hover_css( $attributes, $device = '' ) { $css = []; $card_hover_border = ! empty( $attributes['cardBorder'] ) ? Border::get_hover_css( $attributes['cardBorder'], '', $device ) : array(); if ( ! empty( $attributes['cardBgHoverColor'] ) ) { $css['background'] = $attributes['cardBgHoverColor']; } return array_merge( $css, $card_hover_border, BoxShadow::get_hover_css( $attributes['cardBoxShadow'], '', $device ), ); } public function get_card_padding_css( $attributes, $device = '' ) { return Dimensions::get_css( $attributes['cardPadding'] ?? [], 'padding', $device ); } // Taxonomy Title Start public function get_post_title_css( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['postTitleColor'] ) ) { $css['color'] = $attributes['postTitleColor']; } if ( ! empty( $attributes['postBackgroundColor'] ) ) { $css['background'] = $attributes['postBackgroundColor']; } $typographyValueGlobal = ! empty( $attributes['postTitleTypographyGlobal'] ) ? $attributes['postTitleTypographyGlobal'] : []; $typography = Typography::get_css($attributes['postTitleTypography'] ?? [], [ 'weight' => '500', ], $device, $typographyValueGlobal); $postpadding = Dimensions::get_css( $attributes['postPadding'] ?? [], 'padding', $device ); $border = Border::get_css($attributes['postBorder'] ?? [], [ 'unitWidth' => 'px', 'unitRadius' => 'px', ], $device); return array_merge( $css, $typography, $postpadding, $border ); } public function get_post_hover_title_css( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['postTitleHoverColor'] ) ) { $css['color'] = $attributes['postTitleHoverColor']; } if ( ! empty( $attributes['hoverPostBackgroundColor'] ) ) { $css['background'] = $attributes['hoverPostBackgroundColor']; } return $css; } public function get_post_active_title_css( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['postTitleActiveColor'] ) ) { $css['color'] = $attributes['postTitleActiveColor']; } if ( ! empty( $attributes['activePostBackgroundColor'] ) ) { $css['background'] = $attributes['activePostBackgroundColor']; } $border = Border::get_css($attributes['activePostBorder'] ?? [], [ 'unitWidth' => 'px', 'unitRadius' => 'px', ], $device); return array_merge( $css, $border ); } // Post Title End public function get_button_css( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['buttonColor'] ) ) { $css['color'] = $attributes['buttonColor']; } if ( ! empty( $attributes['buttonBgColor'] ) ) { $css['background'] = $attributes['buttonBgColor']; } // Display if ( isset( $attributes['buttonPosition'][ 'value' . $device ] ) ) { $css['display'] = $attributes['buttonPosition'][ 'value' . $device ]; } $typographyValueGlobal = ! empty( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : []; return array_merge( Typography::get_css( $attributes['buttonTypography'] ?? [], '', $device, $typographyValueGlobal ), Border::get_css( $attributes['buttonBorder'] ?? [], '', $device ), Dimensions::get_css( $attributes['buttonPadding'] ?? [], 'padding', $device ), $css ); } public function get_button_hover_css( $attributes, $device = '' ) { $css = []; $button_hover_border = ! empty( $attributes['buttonBorder'] ) ? Border::get_hover_css( $attributes['buttonBorder'], '', $device ) : array(); if ( ! empty( $attributes['buttonHoverColor'] ) ) { $css['color'] = $attributes['buttonHoverColor']; } if ( ! empty( $attributes['buttonHoverBgColor'] ) ) { $css['background'] = $attributes['buttonHoverBgColor']; } return array_merge( $button_hover_border, $css ); } // Icon Style public function get_icons( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['iconBgColor'] ) ) { $css['background'] = $attributes['iconBgColor']; } return array_merge( Dimensions::get_css( $attributes['iconPadding'] ?? [], 'padding', $device ), Dimensions::get_css( $attributes['iconBorderRadius'] ?? [], 'border-radius', $device ), $css ); } public function get_icons_svg( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['iconsSize'] ) ) { $css['width'] = $attributes['iconsSize'] . 'px'; } if ( ! empty( $attributes['iconsSize'] ) ) { $css['height'] = $attributes['iconsSize'] . 'px'; } return array_merge( $css ); } public function get_icon_svg_path( $attributes, $device = '' ) { $css = []; if ( ! empty( $attributes['iconColor'] ) ) { $css['fill'] = $attributes['iconColor']; } return array_merge( $css ); } public function get_card_wrapper( $attributes, $device = '' ) { $css = []; if ( $attributes['taxonomyLayout'] === 'flex' ) { $css['display'] = 'grid'; $css['gap'] = '1.5em'; if ( $device === 'Tablet' ) { $css['grid-template-columns'] = 'repeat(2, 1fr)'; } elseif ( $device === 'Mobile' ) { $css['grid-template-columns'] = 'repeat(1, 1fr)'; } elseif ( ! empty( $attributes['itemsPerRow'] ) ) { $css['grid-template-columns'] = 'repeat(' . $attributes['itemsPerRow'] . ', 1fr)'; } } return array_merge( $css ); } public function render_callback( $attributes, $content, $block_instance ) { $content = ''; return parent::render_callback( $attributes, $content, $block_instance ); } // Markup Start protected function inherit_selected_terms( array $active_taxonomy, array $selected_terms, string $selected_post_type, bool $show_inherit ): array { if ( ! $show_inherit || empty( $active_taxonomy ) ) { return $selected_terms; } $queried_object = get_queried_object(); if ( is_tax() || is_post_type_archive() ) { foreach ( $active_taxonomy as $taxonomy ) { if ( isset( $queried_object->taxonomy ) && $queried_object->taxonomy === $taxonomy ) { $selected_terms[ $taxonomy ] = [ $queried_object->term_id ]; } else { $terms = get_terms([ 'taxonomy' => $taxonomy, 'hide_empty' => true ]); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { $selected_terms[ $taxonomy ] = wp_list_pluck( $terms, 'term_id' ); } } } } elseif ( is_singular( $selected_post_type ) && $queried_object instanceof \WP_Post ) { foreach ( $active_taxonomy as $taxonomy ) { $terms = get_the_terms( $queried_object->ID, $taxonomy ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { $selected_terms[ $taxonomy ] = wp_list_pluck( $terms, 'term_id' ); } } } else { foreach ( $active_taxonomy as $taxonomy ) { $terms = get_terms([ 'taxonomy' => $taxonomy, 'hide_empty' => true ]); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { $selected_terms[ $taxonomy ] = wp_list_pluck( $terms, 'term_id' ); } } }//end if return $selected_terms; } /** * Taxonomy Wise Query */ protected function build_term_query( string $taxonomy, int $term_id, string $post_type, int $per_page, string $orderby, string $order ): \WP_Query { return new \WP_Query([ 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => $per_page, 'orderby' => $orderby, 'order' => $order, 'tax_query' => [ [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $term_id, ] ], ]); } /** * Accordion Open Use current post ID Check */ protected function should_open_section( \WP_Query $query, int $current_post_id ): bool { if ( ! $current_post_id || ! $query->have_posts() ) { return false; } $open = false; while ( $query->have_posts() ) { $query->the_post(); if ( get_the_ID() === $current_post_id ) { $open = true; break; } } $query->rewind_posts(); wp_reset_postdata(); return $open; } /** * Post ID Use Active class */ protected function render_posts_list( \WP_Query $query, bool $show_post, int $current_post_id ): void { if ( ! $query->have_posts() || ! $show_post ) { return; } echo '