Sindbad~EG File Manager

Current Path : /home/xiedrke/entrepot/wp-content/themes/realpro/elementor/widgets/
Upload File :
Current File : /home/xiedrke/entrepot/wp-content/themes/realpro/elementor/widgets/post-list.php

<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Elementor List Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.0
 */

class Elementor_Realpro_Post_List extends \Elementor\Widget_Base {

	public function get_name() {
		return 'realpro-post-list';
	}

	public function get_title() {
		return esc_html__( 'Realpro: Post List ', 'realpro' );
	}

	public function get_icon() {
		return 'eicon-post';
	}

	public function get_categories() {
		return ['realpro'];
	}

	public function get_base() {
		return basename( __FILE__, '.php' );
	}

    protected function register_controls() {
		$this->_register_content_main();
	}

    protected function _register_content_main() {
        $this->start_controls_section(
			'content',
			[
				'label' => esc_html__( 'Post', 'realpro' )
			]
		);

		$this->add_control(
			'cat_id',
			array(
				'label'   => esc_html__( 'Select Category', 'realpro' ),
				'default' => 'all',
				'type'    => \Elementor\Controls_Manager::SELECT,
				'options' => get_cat_taxonomy( 'category',
					array( 'all' => esc_html__( 'All', 'realpro' ) ) ),
			)
		);

		$this->add_responsive_control(
			'posts_per_page',
			array(
				'label'   => esc_html__( 'Number Post', 'realpro' ),
				'default' => '3',
				'type'    => \Elementor\Controls_Manager::NUMBER,
			)
		);

		$this->add_responsive_control(
			'columns',
			array(
				'label'          => esc_html__( 'Columns', 'realpro' ),
				'type'           => \Elementor\Controls_Manager::SELECT,
				'options'        => array(
					'1' => '1',
					'2' => '2',
					'3' => '3',
					'4' => '4',
				),
                'selectors'      => array(
					'{{WRAPPER}}' => '--realpro-post-item-column: {{VALUE}};',
				),
				'default'        => '3',
				'tablet_default' => '2',
				'mobile_default' => '1',
			)
		);

		$this->add_control(
			'orderby',
			array(
				'label'   => esc_html__( 'Order by', 'realpro' ),
				'type'    => \Elementor\Controls_Manager::SELECT,
				'options' => array(
					'popular' => esc_html__( 'Popular', 'realpro' ),
					'recent'  => esc_html__( 'Date', 'realpro' ),
					'title'   => esc_html__( 'Title', 'realpro' ),
					'random'  => esc_html__( 'Random', 'realpro' ),
				),
				'default' => 'recent',
			)
		);

		$this->add_control(
			'order',
			array(
				'label'   => esc_html__( 'Order by', 'realpro' ),
				'type'    => \Elementor\Controls_Manager::SELECT,
				'options' => array(
					'asc'  => esc_html__( 'ASC', 'realpro' ),
					'desc' => esc_html__( 'DESC', 'realpro' ),
				),
				'default' => 'asc',
			)
		);

        $this->add_control(
			'show_date',
			array(
				'label'     => esc_html__( 'Show Date', 'realpro' ),
				'type'      => \Elementor\Controls_Manager::SWITCHER,
				'label_on'  => esc_html__( 'Yes', 'realpro' ),
				'label_off' => esc_html__( 'No', 'realpro' ),
				'default'   => 'no',
			)
		);


        $this->end_controls_section();
    }

	protected function render() {
        $settings = $this->get_settings_for_display();

		$query_args = array(
			'post_status'         => 'publish',
			'post_type'           => 'post',
			'posts_per_page'      => absint($settings['posts_per_page']),
			'order'               => ( 'asc' == $settings['order'] ) ? 'asc' : 'desc',
			'ignore_sticky_posts' => true,
		);

		if ( $settings['cat_id'] && $settings['cat_id'] != 'all' ) {
			$query_args['cat'] = absint( $settings['cat_id'] );
		}

		switch ( $settings['orderby'] ) {
			case 'recent':
				$query_args['orderby'] = 'post_date';
				break;
			case 'title':
				$query_args['orderby'] = 'post_title';
				break;
			case 'popular':
				$query_args['orderby'] = 'comment_count';
				break;
			default: // random
				$query_args['orderby'] = 'rand';
		}

        $this->render_data_content_post( $settings, $query_args );

	}

    protected function render_item_post($settings ) {
		?>
		<div class="realpro-item-post">

			<?php $this->render_image_post(); ?>
            <div class="box-ct">
                <?php $this->render_title_post(); ?>
				<div class="post-meta">


                <?php
                    if($settings['show_date'] == 'yes') {
						?>
							<?php
								$this->render_post_date();
							?>
                        <?php 
                    }

					$this->render_post_category();
					?>
						</div>
					<?php

					$thim_excerpt =  get_the_excerpt();

					if ($thim_excerpt != '' ) {
						echo '<div class="post-desc">'; the_excerpt(); echo '</div>';
					}
                ?>
				
            </div>
		</div>
		<?php
	}

	protected function render_data_content_post( $settings, $query_args ) {

		$the_query  = new \WP_Query( $query_args );

		$class_item  = 'realpro-post__item';
		if ( $the_query->have_posts()) {
			?>
			<div class="realpro-post__inner">
				<?php
				while ( $the_query->have_posts() ) {
					$the_query->the_post();
					?>
						<div <?php post_class( $class_item ); ?>>
							<?php $this->render_item_post( $settings ); ?>
						</div> <?php
					}
				?>
			</div>
			<?php
		} 

		wp_reset_postdata();
	}

    protected function render_image_post( ) {
		?>
		<div class="realpro-post-image">
			<a href="<?php echo esc_url( get_the_permalink() ) ?>" title="<?php the_title(); ?>">
            <?php echo get_the_post_thumbnail(); ?></a>
		</div>
		<?php
	}

    protected function render_title_post( ) {
		?>
		<h5 class="realpro-post-title">
			<a href="<?php echo esc_url( get_the_permalink() ) ?>"><?php the_title(); ?></a>
		</h5>
	<?php }

    protected function render_post_date() {
        ?>
            <span class="post-date"><?php echo thim_get_entry_meta_date(); ?></span>
        <?php
    }

	protected function render_post_category() {
		?>
            <span class="post-cate"><?php echo thim_get_entry_meta_category(); ?></span>
        <?php
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists