OwlCyberSecurity - MANAGER
Edit File: blog-list.php
<?php use Elementor\Widget_Base; use Elementor\Controls_Manager; use Elementor\Group_Control_Typography; use Elementor\Utils; use Elementor\Group_Control_Border; if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly class Chursy_Elementor_Blog_List extends Widget_Base { public function get_name() { return 'chursy_elementor_blog_list'; } public function get_title() { return esc_html__( 'Blog List', 'chursy' ); } public function get_icon() { return 'eicon-posts-ticker'; } public function get_categories() { return [ 'chursy' ]; } public function get_script_depends() { return [ '' ]; } // Add Your Controll In This Function protected function register_controls() { $args = array( 'orderby' => 'name', 'order' => 'ASC' ); $categories = get_categories($args); $cate_array = array(); $arrayCateAll = array( 'all' => esc_html__( 'All categories', 'chursy' ) ); if ( $categories ) { foreach ( $categories as $cate ) { $cate_array[$cate->slug] = $cate->cat_name; } } else { $cate_array[ esc_html__( 'No content Category found', 'chursy' ) ] = 0; } $this->start_controls_section( 'section_content', [ 'label' => esc_html__( 'Content', 'chursy' ), ] ); $this->add_control( 'category', [ 'label' => esc_html__( 'Category', 'chursy' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'all', 'options' => array_merge( $arrayCateAll, $cate_array ), ] ); $this->add_control( 'posts_per_page', [ 'label' => esc_html__( 'Posts Per Page', 'chursy' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 4, ] ); $this->add_control( 'order', [ 'label' => esc_html__('Order', 'chursy'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'desc', 'options' => [ 'asc' => esc_html__('Ascending', 'chursy'), 'desc' => esc_html__('Descending', 'chursy'), ] ] ); $this->add_control( 'orderby', [ 'label' => esc_html__('Order By', 'chursy'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'ID', 'options' => [ 'none' => esc_html__('None', 'chursy'), 'ID' => esc_html__('ID', 'chursy'), 'title' => esc_html__('Title', 'chursy'), 'date' => esc_html__('Date', 'chursy'), 'modified' => esc_html__('Modified', 'chursy'), 'rand' => esc_html__('Rand', 'chursy'), ] ] ); $this->add_control( 'heading', [ 'label' => esc_html__( 'Heading', 'chursy' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Read Blog Article', 'chursy' ), ] ); $this->add_control( 'text_button', [ 'label' => esc_html__( 'Text Button', 'chursy' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'See all blogs', 'chursy' ), ] ); $this->add_control( 'text_button_readmore', [ 'label' => esc_html__( 'Text Button Read more', 'chursy' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Read More', 'chursy' ), ] ); $this->end_controls_section(); /* General */ $this->start_controls_section( 'items_style_section', [ 'label' => esc_html__( 'General', 'chursy' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_responsive_control( 'items_padding', [ 'label' => esc_html__( 'Padding', 'chursy' ), 'type' => \Elementor\Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ], 'selectors' => [ '{{WRAPPER}} .ova-blog-list .item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->add_group_control( \Elementor\Group_Control_Box_Shadow::get_type(), [ 'name' => 'items_box_shadow', 'selector' => '{{WRAPPER}} .ova-blog-list .item', ] ); $this->add_control( 'items_bg', [ 'label' => esc_html__( 'Background', 'chursy' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ova-blog-list .item' => 'background: {{VALUE}}', ], ] ); $this->end_controls_section(); $this->start_controls_section( 'section_heading_style', [ 'label' => esc_html__( 'Heading', 'chursy' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'heading_typography', 'selector' => '{{WRAPPER}} .ova-blog-list .top-heading .heading', ] ); $this->add_control( 'heading_color', [ 'label' => esc_html__( 'Color', 'chursy' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ova-blog-list .top-heading .heading' => 'color: {{VALUE}};', ], ] ); $this->end_controls_section(); //SECTION TAB STYLE TITLE $this->start_controls_section( 'section_title', [ 'label' => esc_html__( 'Title', 'chursy' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'title_typography', 'selector' => '{{WRAPPER}} .ova-blog-list .post-title', ] ); $this->add_control( 'color_title', [ 'label' => esc_html__( 'Color', 'chursy' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ova-blog-list .post-title a' => 'color : {{VALUE}};', ], ] ); $this->add_control( 'color_title_hover', [ 'label' => esc_html__( 'Color Hover', 'chursy' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ova-blog-list .post-title a:hover' => 'color : {{VALUE}};', ], ] ); $this->add_responsive_control( 'margin_title', [ 'label' => esc_html__( 'Margin', 'chursy' ), 'type' => \Elementor\Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', 'em', '%' ], 'selectors' => [ '{{WRAPPER}} .ova-blog-list .post-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->end_controls_section(); //END SECTION TAB STYLE TITLE /* Meta */ $this->start_controls_section( 'section_meta', [ 'label' => esc_html__( 'Meta', 'chursy' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'meta_text_typography', 'selector' => '{{WRAPPER}} .ova-blog-list .item .post-meta .item-meta .right', ] ); $this->add_control( 'meta_text_color', [ 'label' => esc_html__( 'Color', 'chursy' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ova-blog-list .item .post-meta .item-meta .right, {{WRAPPER}} .ova-blog-list .item .post-meta .item-meta .right a' => 'color: {{VALUE}}', ], ] ); $this->add_control( 'meta_text_color_hover', [ 'label' => esc_html__( 'Link Hover', 'chursy' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ova-blog-list .item .post-meta .item-meta .right a:hover' => 'color: {{VALUE}}', ], ] ); $this->end_controls_section(); /* Button */ $this->start_controls_section( 'section_button', [ 'label' => esc_html__( 'Button Read More', 'chursy' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'button_typography', 'selector' => '{{WRAPPER}} .ova-blog-list .item .details-button', ] ); $this->add_control( 'color_button', [ 'label' => esc_html__( 'Color', 'chursy' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ova-blog-list .item .details-button' => 'color : {{VALUE}};', ], ] ); $this->add_control( 'color_hover_button', [ 'label' => esc_html__( 'Color Hover', 'chursy' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ova-blog-list .item .details-button:hover' => 'color : {{VALUE}};', ], ] ); $this->end_controls_section(); } // Render Template Here protected function render() { $settings = $this->get_settings_for_display(); $category = $settings['category']; $posts_per_page = $settings['posts_per_page']; $order = $settings['order']; $orderby = $settings['orderby']; $heading = $settings['heading']; $text_button = $settings['text_button']; $text_button_readmore = $settings['text_button_readmore']; $args = []; if ( $category == 'all' ) { $args = [ 'post_type' => 'post', 'posts_per_page' => $posts_per_page, 'order' => $order, 'orderby' => $orderby, ]; } else { $args = [ 'post_type' => 'post', 'category_name' => $category, 'posts_per_page' => $posts_per_page, 'order' => $order, 'orderby' => $orderby, 'fields' => 'ids' ]; } $blog = new \WP_Query($args); ?> <div class="ova-blog-list"> <div class="top-heading"> <?php if( !empty($heading) ) { ?> <h2 class="heading"> <?php echo esc_html($heading); ?> </h2> <?php } ?> <?php if( !empty($text_button) ){ ?> <a href="<?php echo get_post_type_archive_link('post') ?>" class="read-more"> <?php echo esc_html( $text_button ); ?> </a> <?php } ?> </div> <?php if( $blog->have_posts() ) : while( $blog->have_posts() ) : $blog->the_post(); $categories = get_the_category(); $thumbnail = wp_get_attachment_image_url(get_post_thumbnail_id() , 'chursy_thumbnail' ); ?> <div class="item"> <?php if( has_post_thumbnail() ) { ?> <div class="media"> <img src="<?php echo esc_url( $thumbnail ); ?>" alt="<?php the_title(); ?>"> </div> <?php } ?> <div class="right-item"> <div class="info"> <?php if ( get_the_title() ) { ?> <h2 class="post-title"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"> <?php echo get_the_title(); ?> </a> </h2> <?php } ?> <div class="post-bottom"> <ul class="post-meta"> <li class="item-meta wp-author"> <span class="right post-author"> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"> <?php the_author_meta( 'display_name' ); ?> </a> </span> </li> <li class="item-meta post-date"> <span class="right date"> <?php the_time( get_option( 'date_format' ) ); ?> </span> </li> </ul> </div> </div> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" class="details-button"> <span><?php echo esc_html($text_button_readmore);?></span> <i aria-hidden="true" class="flaticon flaticon-right-arrow-1"></i> </a> </div> </div> <?php endwhile; endif; wp_reset_postdata(); ?> </div> <?php } } $widgets_manager->register( new Chursy_Elementor_Blog_List() );