start_controls_section( 'section_query', [ 'label' => __( 'Query', 'admore-widgets-suite' ), ] ); $this->add_control( 'relation', [ 'label' => __( 'Related By', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'category', 'options' => [ 'category' => __( 'Category', 'admore-widgets-suite' ), 'tag' => __( 'Tags', 'admore-widgets-suite' ), 'author' => __( 'Author', 'admore-widgets-suite' ), ], ] ); $this->add_control( 'posts_per_page', [ 'label' => __( 'Number of Posts', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 3, 'min' => 1, 'max' => 12, ] ); $this->add_control( 'orderby', [ 'label' => __( 'Order By', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'date', 'options' => [ 'date' => __( 'Date', 'admore-widgets-suite' ), 'rand' => __( 'Random', 'admore-widgets-suite' ), 'comment_count' => __( 'Comment Count', 'admore-widgets-suite' ), 'modified' => __( 'Last Modified', 'admore-widgets-suite' ), ], ] ); $this->end_controls_section(); /* ── Layout ── */ $this->start_controls_section( 'section_layout', [ 'label' => __( 'Layout', 'admore-widgets-suite' ), ] ); $this->add_responsive_control( 'columns', [ 'label' => __( 'Columns', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => '3', 'tablet_default' => '2', 'mobile_default' => '1', 'options' => [ '1'=>'1','2'=>'2','3'=>'3','4'=>'4' ], 'selectors' => [ '{{WRAPPER}} .eppro-rp-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ], ] ); $this->add_control( 'show_thumbnail', [ 'label' => __( 'Show Thumbnail', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->add_control( 'show_date', [ 'label' => __( 'Show Date', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->add_control( 'show_excerpt', [ 'label' => __( 'Show Excerpt', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->add_control( 'excerpt_length', [ 'label' => __( 'Excerpt Length (words)', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 15, 'min' => 5, 'condition' => [ 'show_excerpt' => 'yes' ], ] ); $this->add_control( 'show_category', [ 'label' => __( 'Show Category Badge', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->add_control( 'section_title', [ 'label' => __( 'Section Title', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => __( 'Related Posts', 'admore-widgets-suite' ), 'dynamic' => [ 'active' => true ], ] ); $this->end_controls_section(); /* ── Style ── */ $this->start_controls_section( 'section_style', [ 'label' => __( 'Cards', 'admore-widgets-suite' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'card_bg', [ 'label' => __( 'Card Background', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => [ '{{WRAPPER}} .eppro-rp-card' => 'background: {{VALUE}};' ], ] ); $this->add_control( 'card_radius', [ 'label' => __( 'Border Radius', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'min' => 0, 'max' => 30 ] ], 'default' => [ 'size' => 10 ], 'selectors' => [ '{{WRAPPER}} .eppro-rp-card' => 'border-radius: {{SIZE}}px; overflow: hidden;' ], ] ); $this->add_control( 'img_height', [ 'label' => __( 'Image Height', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'min' => 80, 'max' => 400 ] ], 'default' => [ 'size' => 180 ], 'selectors' => [ '{{WRAPPER}} .eppro-rp-thumb img' => 'height: {{SIZE}}px;' ], 'condition' => [ 'show_thumbnail' => 'yes' ], ] ); $this->add_control( 'title_color', [ 'label' => __( 'Title Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#1e293b', 'selectors' => [ '{{WRAPPER}} .eppro-rp-title a' => 'color: {{VALUE}};' ], ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'title_typo', 'selector' => '{{WRAPPER}} .eppro-rp-title', ] ); $this->add_control( 'title_hover_color', [ 'label' => __( 'Title Hover Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .eppro-rp-title a:hover' => 'color: {{VALUE}};' ], ] ); $this->add_control( 'excerpt_color', [ 'label' => __( 'Excerpt Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#64748b', 'selectors' => [ '{{WRAPPER}} .eppro-rp-excerpt' => 'color: {{VALUE}};' ], 'separator' => 'before', ] ); $this->add_control( 'date_color', [ 'label' => __( 'Date Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#94a3b8', 'selectors' => [ '{{WRAPPER}} .eppro-rp-date' => 'color: {{VALUE}};' ], ] ); $this->add_control( 'cat_color', [ 'label' => __( 'Category Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .eppro-rp-cat' => 'color: {{VALUE}};' ], ] ); $this->add_control( 'card_hover_bg', [ 'label' => __( 'Card Hover Background', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'separator' => 'before', 'selectors' => [ '{{WRAPPER}} .eppro-rp-card:hover' => 'background: {{VALUE}};' ], ] ); $this->add_group_control( \Elementor\Group_Control_Box_Shadow::get_type(), [ 'name' => 'card_shadow', 'selector' => '{{WRAPPER}} .eppro-rp-card', ] ); $this->add_control( 'section_title_color', [ 'label' => __( 'Section Title Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'separator' => 'before', 'selectors' => [ '{{WRAPPER}} .eppro-rp-heading' => 'color: {{VALUE}};' ], ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'section_title_typo', 'selector' => '{{WRAPPER}} .eppro-rp-heading', ] ); $this->end_controls_section(); $this->eppro_register_entrance_animation_controls(); } protected function render(): void { $s = $this->get_settings_for_display(); $relation = $s['relation'] ?? 'category'; $num = intval( $s['posts_per_page'] ?? 3 ); $orderby = $s['orderby'] ?? 'date'; $post_id = get_the_ID(); $post_type = get_post_type( $post_id ); $tax_query = []; if ( 'category' === $relation ) { $cats = wp_get_post_categories( $post_id ); if ( $cats ) { $tax_query[] = [ 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $cats ]; } } elseif ( 'tag' === $relation ) { $tags = wp_get_post_tags( $post_id, [ 'fields' => 'ids' ] ); if ( $tags ) { $tax_query[] = [ 'taxonomy' => 'post_tag', 'field' => 'term_id', 'terms' => $tags ]; } } $args = [ 'post_type' => $post_type, 'posts_per_page' => $num, 'post__not_in' => [ $post_id ], 'orderby' => $orderby, 'no_found_rows' => true, 'ignore_sticky_posts' => true, ]; if ( 'author' === $relation ) { $args['author'] = (int) get_post_field( 'post_author', $post_id ); } elseif ( ! empty( $tax_query ) ) { $args['tax_query'] = $tax_query; } $query = new WP_Query( $args ); if ( ! $query->have_posts() ) { wp_reset_postdata(); if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { echo '
' . esc_html__( 'Related Posts', 'admore-widgets-suite' ) . '
' . esc_html__( 'Related posts will appear here on singular post pages.', 'admore-widgets-suite' ) . '