<?php
 
add_filter( 'ppt_blocks_args', 	array('block_blog7',  'data') );
add_action( 'blog7',  		array('block_blog7', 'output' ) );
add_action( 'blog7-css',  	array('block_blog7', 'css' ) );
add_action( 'blog7-js',  	array('block_blog7', 'js' ) );

class block_blog7 {

	function __construct(){}		

	public static function data($a){  global $CORE;
  
		$a['blog7'] = array(
			"name" 	=> "Blog 7",
			"image"	=> "blog7.jpg",
			"cat"	=> "blog",
			"desc" 	=> "", 
			"widget" => "ppt-blog",	
			"data" 	=> array( ),
			"order" => 7,
			"defaults" => array(),
						
		);		
		
		return $a;
	
	} public static function output(){ global $CORE, $wpdb, $blog_settings, $settings, $CORE_UI;
 		
		 
		 $df = array(
		 	 
			"show" => 3,
			"cat" => array(),
			"pagenav" => 1
		 		 
		 );
		 
		 if(is_array($blog_settings) && !empty($blog_settings)){		 	
			 
			 $df['show'] = $blog_settings['show'];
			 $df['cat'] = $blog_settings['cat'];
			 $df['pagenav'] = $blog_settings['pagenav'];
		 }
	 
	 // MAIN QUERY  
	 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;   
	 if(isset($_GET['home_paged']) && is_numeric($_GET['home_paged'])){
		$paged = $_GET['home_paged'];
	}
	$args = array(
	'post_type' 		=> 'post',
	'posts_per_page' 	=> $df['show'], 
	'orderby' 			=> 'date',
	"order" 			=> "desc",
	'paged' 			=> $paged, 
	);
	
	if(!empty($df['cat'])){
	$args['tax_query'] = array( array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $df['cat']   )  );		
	}
	
	$wp_query = new WP_Query($args); 
	$tt = $wpdb->get_results($wp_query->request, OBJECT);

	    // COUNT TOTALS
		if($df['pagenav']){
			$totalBlogs = $wp_query->found_posts; 
			$totalPages = 1;
			
			if($totalBlogs > $args['posts_per_page'] && $args['posts_per_page'] > 0){
				$totalPages = ceil($totalBlogs/$args['posts_per_page']);
			}
		}

ob_start();
if(!empty($tt)){
             
?>

<section class="section-60">
  <div class="container">
    <div class="row">
      <?php foreach($tt as $p){
         
          global $post;
          
        $post = get_post($p->ID);
		  
		$day 	= date("d", strtotime(get_the_date('Y-m-d',$post->ID)));
		$month 	= date("M", strtotime(get_the_date('Y-m-d',$post->ID)));
		$year 	= date("Y", strtotime(get_the_date('Y-m-d',$post->ID)));
		
         
    ?>
      <div class="col-md-4">
      
       <article class="mb-4 mb-sm-0">
      <figure class="mb-4" ppt-border1> <a href="<?php echo get_permalink($post->ID); ?>"> <img src="<?php echo do_shortcode('[IMAGE pathonly=1]'); ?>" alt="<?php echo strip_tags(do_shortcode('[TITLE]')); ?>" class="img-fluid"> </a> </figure>
      
        
          <div class="mb-1">
            <a href="<?php echo get_permalink($post->ID); ?>" class="text-dark fs-6 text-600">
          
              <?php echo $post->post_title; ?>
             
            </a>
          </div>
          <div class="opacity-5">
            <?php echo do_shortcode("[EXCERPT limit=100]"); ?>...
          </div>
       
      </div>
       </article>
      <?php }?>
    </div>
  </div>
</section>

<?php
}
		$output = ob_get_contents();
		ob_end_clean();
		
echo ppt_theme_block_output($output, $blog_settings, array("blog", "blog7"));


// PAGE NAV
if($df['pagenav']){ 
	echo '<div class="container"><div class="row"><div class="col-12 mb-4"><div class="my-4 pt-3  mobile-mb-4 mobile-pb-4">'.$CORE->PAGENAV(1,$totalBlogs,$totalPages).'</div></div></div></div>';
}
	
	}
	
		public static function css(){
		ob_start();
		?>
<style>

article .post-date {
    float: left;
    margin-right: 10px;
    text-align: center;
}
article .post-date .day {
  
    border-radius: 2px 2px 0 0;
    color: #ccc;
    display: block;
    font-size: 18px;
    font-weight: 900;
    padding: 10px;
}

article .post-date .month {
    display: block;
 
    border-radius: 0 0 2px 2px;
    color: #fff;
    font-size: .8em;
    line-height: 1.8;
    padding: 1px 10px;
    text-transform: uppercase;
}
</style>
<?php	
		$output = ob_get_contents();
		ob_end_clean();
		echo $output;
		 }
		 
		public static function js(){
		return "";
		ob_start();
		?>
<?php	
		$output = ob_get_contents();
		ob_end_clean();
		echo $output;
		 }	
		 	
}

?>
