Sindbad~EG File Manager

Current Path : /home/copmadinaarea/www/wp-content__80fcb17/plugins/adorechurch-core/widgets/
Upload File :
Current File : /home/copmadinaarea/www/wp-content__80fcb17/plugins/adorechurch-core/widgets/selected_post.php

<?php
/*** Widget code for Selected Post ***/
class adore_core_selected_post extends WP_Widget {
	// constructor
	public function __construct() {
		 $widget_ops = array('description' => __( 'Display latest and selected post of different post type.','adorechurch-core') );
         parent::__construct(false, $name = __('(N) Selected Post','adorechurch-core'), $widget_ops);
	}
	// widget form creation
	public function form($instance) {
		// Check values
		if( $instance) {
			 $title = esc_attr($instance['title']);
			 $type = esc_attr($instance['type']);
			 $number = esc_attr($instance['number']);
		} else {
			 $title = '';
			 $type = '';
			 $number = '';
		}
	?>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e('Title', 'adorechurch-core'); ?></label>
            <input class="spTitle" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
        </p>
        
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('type')); ?>"><?php _e('Select Post Type', 'adorechurch-core'); ?></label>
            <select class="spType" id="<?php echo esc_attr($this->get_field_id('type')); ?>" name="<?php echo esc_attr($this->get_field_name('type')); ?>">
                <?php
                $post_types = get_post_types( array('_builtin' => false), 'names' ); 
                array_unshift($post_types, "post");
                if(($key = array_search('wpcf7_contact_form', $post_types)) !== false){
				unset($post_types[$key]);
				}
                if(!empty($post_types)){
                    foreach ( $post_types as $post_type ) {
                        $activePost = ($type == $post_type)? 'selected' : '';
                       echo '<option value="'. $post_type .'" '.$activePost.'>' . $post_type . '</p>';
                    }
                }else{
                    echo '<option value="no">'.__('No Post Type Found.','adorechurch-core').'</option>';
                }
                ?>
            </select> 
        </p>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('number')); ?>"><?php _e('Number of posts to show', 'adorechurch-core'); ?></label>
            <input id="<?php echo esc_attr($this->get_field_id('number')); ?>" name="<?php echo esc_attr($this->get_field_name('number')); ?>" type="text" value="<?php echo esc_attr($number); ?>" />
        </p> 
	<?php
	}
	// update widget
	public function update($new_instance, $old_instance) {
		  $instance = $old_instance;
		  // Fields
		  $instance['title'] = strip_tags($new_instance['title']);
		  $instance['type'] = strip_tags($new_instance['type']);
		  $instance['number'] = strip_tags($new_instance['number']);
		  
		 return $instance;
	}
	// display widget
	public function widget($args, $instance) {
	   extract( $args );
	   // these are the widget options
	   $post_title = apply_filters('widget_title', $instance['title']);
	   $type = apply_filters('widget_type', $instance['type']);
	   $number = apply_filters('widget_number', $instance['number']);
	   
	   $numberPost = (!empty($number))? $number : 3 ;	
	   	   
	   echo ''.$args['before_widget'];
		
		if( !empty($instance['title']) ){
			echo ''.$args['before_title'];
			echo apply_filters('widget_title',$instance['title'], $instance, $this->id_base);
			echo ''.$args['after_title'];
		}
		$posts = query_posts(array('order'=>'DESC', 'post_type' => $type, 'posts_per_page' => $numberPost, 'post_status' => 'publish'));
		if(!empty($posts)){ 
			echo '<ul>';
			 foreach($posts as $post){ 
			 	if($type=='event'){
					$event_post = get_post_custom($post->ID);
					$postDate = strtotime($event_post['imic_event_start_dt'][0]);	
				}elseif($type=='sermon'){
					$sermon_post = get_post_custom($post->ID);
					$postDate = strtotime($sermon_post['imic_sermon_date'][0]);
					if($postDate != ''){
						$postDate = $postDate;
					}
					else {
			 			$postDate =  strtotime($post->post_date);
					}
				}else{
			 		$postDate =  strtotime($post->post_date);					
				}
				$postImage = get_the_post_thumbnail( $post->ID, '600x400', array('class' => "img-thumbnail") );
				echo '<li class="clearfix">';
						  	if ( !empty($postImage)) :
						  		echo'<a href="'.esc_url(get_permalink($post->ID)).'" class="media-box post-image">'.$postImage.'</a>';
						 	endif;
				echo '	  
						<div class="widget-blog-content"><a href="'.esc_url(get_permalink($post->ID)).'">'.$post->post_title.'</a>
						<span class="meta-data"><i class="fa fa-calendar"></i>'.__(' on ','adorechurch-core').esc_attr(adorechurch_date_localization(get_option('date_format'),$postDate)).'</span>
						</div>
					</li>';					
					}		
			echo '</ul>';
		}else{
			echo __('No Posts ','adorechurch-core').$type.__('Found','adorechurch-core');		
		}
   
	   echo ''.$args['after_widget'];
	}
}
// register widget
add_action( 'widgets_init', function(){
	register_widget( 'adore_core_selected_post' );
});
?>

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