<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly class TH90_W_Tax extends \Elementor\Widget_Base { public function get_name() { return 'w-tax'; } public function get_title() { return __( 'Taxonomy', 'atlas-core' ); } public function get_keywords() { return [ 'tags', 'category', 'categories' ]; } public function get_icon() { return 'eicon-tags th90-widget-icon'; } public function get_categories() { return [ sanitize_key( wp_get_theme()->name ) . '-elements' ]; } public function controls_general() { $this->start_controls_section( 'section_general', [ 'label' => __( 'General', 'atlas-core' ), ] ); /*$this->add_control( 'show_count', [ 'label' => esc_html__('Show total posts count?', 'atlas-core'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__('Yes', 'atlas-core'), 'label_off' => esc_html__('No', 'atlas-core'), 'default' => 'no', ] );*/ $this->add_control( 'layout', [ 'label' => esc_html__( 'Style', 'elementor' ), 'type' => \Elementor\Controls_Manager::CHOOSE, 'toggle' => false, 'default' => 'hero', 'options' => [ 'hero' => [ 'title' => esc_html__( 'Block Hero', 'elementor' ), 'icon' => 'eicon-editor-list-ul', ], 'grid' => [ 'title' => esc_html__( 'Grid', 'elementor' ), 'icon' => 'eicon-gallery-grid', ], ], ] ); $this->add_responsive_control( 'columns', [ 'label' => __( 'Columns', 'atlas-core' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'min' => 1, 'max' => 15, ], ], 'selectors' => [ '{{WRAPPER}} .tax-grid, {{WRAPPER}} .tax-hero' => 'grid-template-columns: repeat({{SIZE}}, 1fr);', ], ] ); $this->add_responsive_control( 'item_space', [ 'label' => esc_html__( 'Taxonomy item space', 'atlas-core' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'size_units' => [ 'px' ], 'range' => [ 'px' => [ 'min' => 0, 'max' => 200, ], ], 'selectors' => [ '{{WRAPPER}} .tax-grid, {{WRAPPER}} .tax-hero' => 'grid-gap: {{SIZE}}{{UNIT}};', ], ] ); /*$this->add_responsive_control( 'tax_radius', [ 'label' => esc_html__( 'Cloud radius', 'atlas-core' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'size_units' => [ 'px' ], 'range' => [ 'px' => [ 'min' => 0, 'max' => 200, ], ], 'selectors' => [ '{{WRAPPER}} a.term-cloud' => 'border-radius: {{SIZE}}{{UNIT}};', ], ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => '_tax_title_typo', 'label' => esc_html__( 'Taxonomy title typography', 'atlas-core' ), 'selector' => '{{WRAPPER}} .cloud-title', ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => '_tax_count_typo', 'label' => esc_html__( 'Taxonomy count typography', 'atlas-core' ), 'selector' => '{{WRAPPER}} .cloud-count', ] );*/ $this->end_controls_section(); } public function controls_query() { $controls = new TH90_Controls(); $controls->tax_query_default( $this ); } protected function register_controls() { $this->controls_general(); $this->controls_query(); /* Widget Boxed */ $controls = new TH90_Controls(); $controls->box_settings( $this ); } /** * Render the widget output on the frontend. * * Written in PHP and used to generate the final HTML. */ protected function render() { global $block_id; $block_id++; $atts = $this->get_settings_for_display(); $atts['categories'] = ! empty( $atts['categories'] ) ? implode( ',', $atts['categories'] ) : ''; $atts['tags'] = ! empty( $atts['tags'] ) ? implode( ',', $atts['tags'] ) : ''; $count = 0; $wrapper_classes = array_merge( array( 'th90-block', 'block-tax', ), th90_box_class( $atts ) ); ?> <div id="th90-block_<?php echo absint( $block_id ); ?>" class="<?php echo esc_attr( implode( ' ', array_filter( $wrapper_classes ) ) ); ?>"> <?php th90_box_heading( $atts ); /* Term Query */ if ( 'category' == $atts['taxonomy'] ) { if( 'yes' == $atts['selected_cats'] ) { $terms = get_terms( array( 'taxonomy' => 'category', 'include' => $atts['categories'], 'hide_empty' => $atts['hide_empty'] ? true : false, ) ); } else { $terms = get_terms( array( 'taxonomy' => 'category', 'orderby' => $atts['orderby'], 'order' => $atts['order'], 'number' => absint( $atts['number'] ), 'hide_empty' => 'yes' == $atts['hide_empty'] ? true : false, ) ); } } else { if( 'yes' == $atts['selected_tags'] ) { $terms = get_terms( array( 'taxonomy' => 'post_tag', 'include' => $atts['tags'], 'hide_empty' => $atts['hide_empty'] ? true : false, ) ); } else { $terms = get_terms( array( 'taxonomy' => 'post_tag', 'orderby' => $atts['orderby'], 'order' => $atts['order'], 'number' => absint( $atts['number'] ), 'hide_empty' => 'yes' == $atts['hide_empty'] ? true : false, ) ); } } if ( ! empty( $terms ) ) { ?> <div class="tax-<?php echo $atts['layout']; ?>"> <?php foreach ( $terms as $term ) { $atts['term_id'] = $term->term_id; $atts['term_count'] = $term->count; $atts['term_name'] = $term->name; $count++; get_template_part( 'template-parts/term/term', $atts['layout'], array( 'block' => $atts, 'count' => $count, ) ); } ?> </div> <?php } ?> </div> <?php } /** * Render the widget output in the editor. * * Written as a Backbone JavaScript template and used to generate the live preview. */ protected function content_template() { } }