start_controls_section( 'section_colormag_featured_posts_block_2_title_manage', array( 'label' => esc_html__( 'Block Title', 'colormag' ), ) ); $this->add_control( 'widget_title', array( 'label' => esc_html__( 'Title:', 'colormag' ), 'type' => Controls_Manager::TEXT, 'placeholder' => esc_html__( 'Add your custom block title', 'colormag' ), 'label_block' => true, ) ); $this->end_controls_section(); // Widget design section $this->start_controls_section( 'section_colormag_featured_posts_block_2_design_manage', array( 'label' => esc_html__( 'Widget Title', 'colormag' ), 'tab' => Controls_Manager::TAB_STYLE, ) ); $this->add_control( 'widget_title_color', array( 'label' => esc_html__( 'Color:', 'colormag' ), 'type' => Controls_Manager::COLOR, 'default' => '#289dcc', 'scheme' => array( 'type' => Scheme_Color::get_type(), 'value' => Scheme_Color::COLOR_1, ), 'selectors' => array( '{{WRAPPER}} .tg-module-wrapper .module-title span' => 'background-color: {{VALUE}}', '{{WRAPPER}} .tg-module-wrapper .module-title' => 'border-bottom-color: {{VALUE}}', ), ) ); $this->add_control( 'widget_title_text_color', array( 'label' => esc_html__( 'Text Color:', 'colormag' ), 'type' => Controls_Manager::COLOR, 'default' => '#ffffff', 'scheme' => array( 'type' => Scheme_Color::get_type(), 'value' => Scheme_Color::COLOR_1, ), 'selectors' => array( '{{WRAPPER}} .tg-module-wrapper .module-title span' => 'color: {{VALUE}}', ), ) ); $this->end_controls_section(); // Widget posts section $this->start_controls_section( 'section_colormag_featured_posts_block_2_posts_manage', array( 'label' => esc_html__( 'Posts', 'colormag' ), ) ); $this->add_control( 'posts_number', array( 'label' => esc_html__( 'Number of posts to display:', 'colormag' ), 'type' => Controls_Manager::TEXT, 'default' => 2, ) ); $this->add_control( 'offset_posts_number', array( 'label' => esc_html__( 'Offset Posts:', 'colormag' ), 'type' => Controls_Manager::TEXT, ) ); $this->end_controls_section(); // Widget filter section $this->start_controls_section( 'section_colormag_featured_posts_block_2_filter_manage', array( 'label' => esc_html__( 'Filter', 'colormag' ), ) ); $this->add_control( 'display_type', array( 'label' => esc_html__( 'Display the posts from:', 'colormag' ), 'type' => Controls_Manager::SELECT, 'default' => 'latest', 'options' => array( 'latest' => esc_html__( 'Latest Posts', 'colormag' ), 'categories' => esc_html__( 'Categories', 'colormag' ), ), ) ); $this->add_control( 'categories_selected', array( 'label' => esc_html__( 'Select categories:', 'colormag' ), 'type' => Controls_Manager::SELECT, 'options' => colormag_elementor_categories(), 'condition' => array( 'display_type' => 'categories', ), ) ); $this->end_controls_section(); } /** * Render ColorMag_Elementor_Widgets_Block_2 widget output on the frontend. * * Written in PHP and used to generate the final HTML. * * @access protected */ protected function render() { $posts_number = $this->get_settings( 'posts_number' ); $display_type = $this->get_settings( 'display_type' ); $offset_posts_number = $this->get_settings( 'offset_posts_number' ); $categories_selected = $this->get_settings( 'categories_selected' ); $args = array( 'posts_per_page' => $posts_number, 'post_type' => 'post', 'ignore_sticky_posts' => true, 'no_found_rows' => true, ); // Display from the category selected if ( 'categories' == $display_type ) { $args[ 'category__in' ] = $categories_selected; } // Offset the posts if ( ! empty( $offset_posts_number ) ) { $args[ 'offset' ] = $offset_posts_number; } // Start the WP_Query Object/Class $get_featured_posts = new \WP_Query( $args ); ?>
get_settings( 'widget_title' ); if ( ! empty( $widget_title ) ) : ?>

get_settings( 'widget_title' ); ?>

have_posts() ) : $get_featured_posts->the_post(); ?>