block_name = 'taxonomy'; $this->styles = array( 'sp_smart_post_blocks_css', 'sp_smart_post_blocks_google_fonts', 'sp_smart_post_blocks_social_icons_style' ); } /** * Renders the Taxonomy block (consolidated single-method version) * * @param array $attributes Block attributes. * @param string $content Existing block content. * @param array $blocks array. * @return string Rendered HTML */ public function render_block( $attributes, $content = '', $blocks = array() ) { if ( Helper::is_editor_page() ) { return $content; } // Get settings with fallbacks. $attributes['page_id'] = get_the_ID(); unset( $attributes['dynamicCss'], $attributes['fontListsEditPage'], $attributes['fontLists'] ); $unique_id = $attributes['uniqueId'] ?? ''; $block_name = sanitize_html_class( $attributes['blockName'] ?? '' ); $layout = $attributes['layout'] ?? 'taxonomy-layout-one'; $no_result_found_text = $attributes['noResultFoundText'] ?? 'No Data Found'; $taxonomy_type = $attributes['taxonomyType'] ?? 'category'; $empty_category = $attributes['emptyCategory'] ?? true; $all_taxonomy_term = $attributes['allTaxonomyTerm'] ?? true; $include_terms = $attributes['SelectTerms'] ?? array(); $exclude_terms = $attributes['excludeTerms'] ?? array(); $limit = $attributes['limit'] ?? 6; $is_layout_five_six = in_array( $layout, array( 'taxonomy-layout-five', 'taxonomy-layout-six' ) ); $align_class = ! empty( $attributes['align'] ) ? 'align' . $attributes['align'] : ''; $title_enable = $attributes['titleEnable'] ?? true; $display_overly_thum = $attributes['displayOverlyThum'] ?? true; $display_overly_hover_thum = $attributes['displayOverlyHoverThum'] ?? true; $after_count = $attributes['afterCount'] ?? ')'; $before_count = $attributes['beforeCount'] ?? '('; $count_enable = $attributes['countEnable'] ?? true; $content_multi_color_bg = $attributes['contentMultiColorBg'] ?? true; $icon = $attributes['icon'] ?? true; $show_hide_divider = $attributes['showHideDivider'] ?? true; $show_excerpt = $attributes['excerptShow'] ?? false; $taxonomy_icon_style = $attributes['taxonomyIconStyle'] ?? ''; $counter_multi_color_bg = $attributes['counterMultiColorBg'] ?? ''; $excerpt_length = $attributes['excerptLength'] ?? 7; $post_card_bg = $attributes['postCardBg'] ?? array(); $image_overlay_color = $attributes['imageOverlayColor'] ?? ''; $image_overlay_hover_color = $attributes['imageOverlayHoverColor'] ?? ''; $image_overlay_custom_color = $attributes['imageOverlayCustomColor'] ?? ''; $image_overlay_custom_hover_color = $attributes['imageOverlayCustomHoverColor'] ?? ''; $image_enable = $attributes['imageEnable'] ?? true; $hover_effect = $attributes['hoverEffect'] ?? 'normal'; $image_overlay = $attributes['imageOverlay'] ?? ''; $hover_animation = $attributes['hoverAnimation'] ?? ''; $title_global_typography_class = isset( $attributes['titleGlobalTypography']['class'] ) ? $attributes['titleGlobalTypography']['class'] : ''; $excerpt_global_typography_class = isset( $attributes['excerptGlobalTypography']['class'] ) ? $attributes['excerptGlobalTypography']['class'] : ''; $counter_global_typography_class = isset( $attributes['counterGlobalTypography']['class'] ) ? $attributes['counterGlobalTypography']['class'] : ''; $base_args = array( 'layout' => $layout, 'title_enable' => $title_enable, 'after_count' => $after_count, 'before_count' => $before_count, 'count_enable' => $count_enable, 'show_excerpt' => $show_excerpt, 'excerpt_length' => $excerpt_length, 'title_global_typography_class' => $title_global_typography_class, 'excerpt_global_typography_class' => $excerpt_global_typography_class, 'counter_global_typography_class' => $counter_global_typography_class, ); $args_five_six = array_merge( $base_args, array( 'image_overlay' => $image_overlay, 'hover_effect' => $hover_effect, 'image_enable' => $image_enable, ) ); $args_default = array_merge( $base_args, array( 'display_overly_thum' => $display_overly_thum, 'display_overly_hover_thum' => $display_overly_hover_thum, 'content_multi_color_bg' => $content_multi_color_bg, 'icon' => $icon, 'show_hide_divider' => $show_hide_divider, 'taxonomy_icon_style' => $taxonomy_icon_style, 'counter_multi_color_bg' => $counter_multi_color_bg, 'hover_animation' => $hover_animation, 'post_card_bg' => $post_card_bg, 'image_overlay_color' => $image_overlay_color, 'image_overlay_hover_color' => $image_overlay_hover_color, 'image_overlay_custom_color' => $image_overlay_custom_color, 'image_overlay_custom_hover_color' => $image_overlay_custom_hover_color, ) ); // Loader markup before fetching terms. ob_start(); ?>
Loading...
render_five_six_layout( $term, $args_five_six ) ); ?> render_default_layout( $term, $args_default ); ?>

$term, 'placeholder_img' => $placeholder_img, 'display_overly_thum' => $display_overly_thum, 'display_overly_hover_thum' => $display_overly_hover_thum, 'post_card_bg' => $post_card_bg, 'image_overlay_color' => $image_overlay_color, 'image_overlay_hover_color' => $image_overlay_hover_color, 'image_overlay_custom_color' => $image_overlay_custom_color, 'image_overlay_custom_hover_color' => $image_overlay_custom_hover_color, 'layout' => $layout, ); $hover = $this->hover_animate( $hover_animation ?? '', $layout ); // --- Inline style variables (overlay effects) --- $style_array = ( 'taxonomy-layout-three' !== $layout ) ? $this->get_style( $args ) : array(); $style_array['--transformValue'] = $hover['transformValue'] ?? ''; $style_array['--initialValue'] = $hover['initialValue'] ?? ''; $inline_style = ''; foreach ( $style_array as $key => $value ) { if ( ! empty( $value ) ) { $inline_style .= esc_attr( $key ) . ':' . esc_attr( $value ) . ';'; } } // --- Counter style for inline badge --- $counter_style_attr = ''; if ( $should_show_count_in_name && $counter_multi_color_bg && ! empty( $term->category_color ) ) { $counter_style_attr = 'background:' . esc_attr( $term->category_color ) . ';'; } // --- Main wrapper background for layout-8 and layout-3 --- $style = array(); $layout_four_eight = array( 'taxonomy-layout-four', 'taxonomy-layout-eight' ); if ( in_array( $layout, $layout_four_eight, true ) ) { $style['background'] = ! empty( $term->category_color ) ? $term->category_color : '#FFFFFF'; } if ( 'taxonomy-layout-three' === $layout ) { $style = array_merge( $style, $this->get_style( $args ) ); } $style_attr = ''; foreach ( $style as $key => $value ) { if ( ! empty( $value ) ) { $style_attr .= esc_attr( $key ) . ':' . esc_attr( $value ) . ';'; } } $should_show_excerpt = $show_excerpt && in_array( $layout, array( 'taxonomy-layout-one', 'taxonomy-layout-two', 'taxonomy-layout-three', 'taxonomy-layout-five', 'taxonomy-layout-six', ), true ); ob_start(); ?>
count ?? '' ); ?>
description ) && $should_show_excerpt ) : ?>

description ?? '', $excerpt_length ) ); ?>

count ); if ( $should_show_before_after_count ) { echo esc_html( $after_count ); } echo ' '; if ( 'taxonomy-layout-three' === $layout ) { $post_label = ( $term->count <= 1 ) ? 'Post' : 'Posts'; echo '' . esc_html( $post_label ) . ''; } ?>
category_thumbnail; if ( empty( $thumbnail_url ) ) { $thumbnail_url = $placeholder_img; } $should_show_excerpt = $show_excerpt && in_array( $layout, array( 'taxonomy-layout-one', 'taxonomy-layout-two', 'taxonomy-layout-three', 'taxonomy-layout-five', 'taxonomy-layout-six', ), true ); ob_start(); ?>
<?php echo esc_attr( $thumbnail_url ); ?>
name ?? '' ); ?> count ?? 0 ); ?>
description ) && $should_show_excerpt ) : ?>

description ?? '', $excerpt_length ) ); ?>

get_overlay_colors( $image_overlay_color, $image_overlay_hover_color, $image_overlay_custom_color, $image_overlay_custom_hover_color, $layout ); $style = array(); // Make sure the thumbnail is a valid URL string. $thumbnail_url = ''; if ( ! empty( $term->category_thumbnail ) ) { if ( is_array( $term->category_thumbnail ) && isset( $term->category_thumbnail['url'] ) ) { $thumbnail_url = $term->category_thumbnail['url']; } elseif ( is_string( $term->category_thumbnail ) ) { $thumbnail_url = $term->category_thumbnail; } } if ( empty( $thumbnail_url ) ) { $thumbnail_url = $placeholder_img; } $style['--bg-url'] = $display_overly_thum ? 'url(' . esc_url( $thumbnail_url ) . ')' : 'none'; $style['--hover-bg-url'] = $display_overly_hover_thum ? 'url(' . esc_url( $thumbnail_url ) . ')' : $this->color_controls( $post_card_bg['hover']['style'] ?? '', $post_card_bg['hover']['solidColor'] ?? '', $post_card_bg['hover']['gradient'] ?? '' ); $style['--overlay-color'] = $get_overlay_colors['overlayColor'] ?? ''; $style['--overlay-hover-color'] = $get_overlay_colors['overlayHoverColor'] ?? ''; return $style; } /** * Renders the five six layout. * * @param object $color_type item data. * @param object $normal_color image url. * @param string $gradient_color of the method. * @param string $type of the method. * @return object. */ protected function color_controls( $color_type, $normal_color, $gradient_color, $type = 'normal' ) { if ( 'normal' === $type ) { $color_type_object = array( 'transparent' => 'transparent', 'color' => $normal_color, 'gradient' => $gradient_color, ); return $color_type_object[ $color_type ] ?? $normal_color; } else { $hover_color_type_object = array( 'transparentHover' => 'transparent', 'colorHover' => $normal_color, 'gradientHover' => $gradient_color, ); return $hover_color_type_object[ $color_type ] ?? $normal_color; } } /** * Renders the five six layout. * * @param object $hover_animation item data. * @param object $layout image url. * @return object. */ protected function hover_animate( $hover_animation, $layout ) { $transform_value = ''; $initial_value = ''; switch ( $hover_animation ) { case 'zoomIn': $transform_value = 'scale(1.05)'; $initial_value = 'scale(1)'; break; case 'zoomOut': $transform_value = 'scale(1)'; $initial_value = 'scale(1.05)'; break; case 'slideLeft': $transform_value = 'scale(1.10) translateX(-10px)'; $initial_value = 'scale(1.10) translateX(3%)'; break; case 'slideRight': $transform_value = 'scale(1.10) translateX(10px)'; $initial_value = 'scale(1.10) translateX(-3%)'; break; default: $transform_value = 'scale(1)'; $initial_value = 'scale(1)'; } if ( 'taxonomy-layout-one' === $layout ) { return array(); } return array( 'transformValue' => $transform_value, 'initialValue' => $initial_value, ); } /** * Renders the five six layout. * * @param string $image_overlay_color item data. * @param string $image_overlay_hover_color item data. * @param string $image_overlay_custom_color item data. * @param string $image_overlay_custom_hover_color item data. * @param string $layout item data. * @return object. */ protected function get_overlay_colors( $image_overlay_color, $image_overlay_hover_color, $image_overlay_custom_color, $image_overlay_custom_hover_color, $layout ) { if ( 'taxonomy-layout-one' === $layout ) { return array(); } $gradient_map = array( 'warm-sunset' => 'linear-gradient(2deg, rgba(244, 66, 70, 0.4) 33.02%, rgba(221, 36, 118, 0.4) 98.51%)', 'ocean-breeze' => 'linear-gradient(1deg, rgba(43, 88, 118, 0.4) 0.5%, rgba(78, 67, 118, 0.4) 99.51%)', 'royal-gold' => 'linear-gradient(1deg, rgba(255, 215, 0, 0.4) 0.5%, rgba(184, 134, 11, 0.4) 99.51%)', 'cool-blues' => 'linear-gradient(1deg, rgba(30, 60, 114, 0.4) 0.5%, rgba(42, 82, 152, 0.4) 99.51%)', 'soft-pastel' => 'linear-gradient(1deg, rgba(252, 227, 138, 0.4) 0.5%, rgba(243, 129, 129, 0.4) 99.51%)', 'elegant-purple' => 'linear-gradient(180deg, rgba(65, 41, 90, 0.4) 0%, rgba(47, 7, 67, 0.4) 100%)', 'energetic-orange' => 'linear-gradient(180deg, rgba(255, 81, 47, 0.4) 0%, rgba(240, 152, 25, 0.4) 100%)', ); $random_color = $this->overlay_random_solid_color( $image_overlay_color ); $random_hover_color = $this->overlay_random_solid_color( $image_overlay_hover_color ); if ( in_array( $image_overlay_color, array( 'multi-gradient', 'multi-solid' ), true ) ) { $overlay_color = $random_color; } elseif ( 'custom' === $image_overlay_color ) { $overlay_color = $image_overlay_custom_color; } else { $overlay_color = $gradient_map[ $image_overlay_color ] ?? 'transparent'; } if ( in_array( $image_overlay_hover_color, array( 'multi-gradient', 'multi-solid' ), true ) ) { $overlay_hover_color = $random_hover_color; } elseif ( 'custom' === $image_overlay_hover_color ) { $overlay_hover_color = $image_overlay_custom_hover_color; } else { $overlay_hover_color = $gradient_map[ $image_overlay_hover_color ] ?? 'transparent'; } return array( 'overlayColor' => $overlay_color, 'overlayHoverColor' => $overlay_hover_color, ); } /** * Renders the five six layout. * * @param object $color_type item data. * @return object. */ protected function overlay_random_solid_color( $color_type = '' ) { if ( 'multi-solid' === $color_type ) { $r = wp_rand( 0, 255 ); $g = wp_rand( 0, 255 ); $b = wp_rand( 0, 255 ); return "rgba($r, $g, $b, 0.7)"; } if ( 'multi-gradient' === $color_type ) { $color_list = array( 'linear-gradient(293deg, rgba(251, 218, 97, .7) -0.37%, rgba(255, 90, 205, .7) 100%)', 'linear-gradient(90deg, rgba(203, 173, 109, .7) 0%, rgba(213, 51, 105, .7) 100%)', 'linear-gradient(90deg, rgba(36, 198, 220, .7) 0%, rgba(81, 74, 157, .7) 100%)', 'linear-gradient(90deg, rgba(255, 224, 0, .7) 0%, rgba(255, 75, 31, .7) 100%)', 'linear-gradient(90deg, rgba(28, 216, 210, .7) 0%, rgba(147, 237, 199, .7) 100%)', 'linear-gradient(90deg, rgba(255, 212, 82, .7) 0%, rgba(84, 74, 125, .7) 100%)', 'linear-gradient(90deg, rgba(91, 134, 229, .7) 0%, rgba(54, 209, 220, .7) 100%)', 'linear-gradient(90deg, rgba(253, 185, 155, .7) 0%, rgba(167, 112, 239, .7) 100%)', ); return $color_list[ array_rand( $color_list ) ]; } return ''; } }