<?php
  /**
    this section for blog
  **/

  $sections = texas_get_section_default(); 
  
  $default = $sections['blog'];
  
  $blog_article_number = get_theme_mod( 'blog_article_number',3);
  
  $blog_url = get_theme_mod( 'blog_url','');  
  
  $blog_categories = get_theme_mod( 'blog_categories','');

  $blog_button_text = get_theme_mod( 'blog_button_text',__( 'Read The Blog', 'texas' ));

?>           
<section id="ct_blog" class="ct_section ct_blog ct_section_10 ">
	<div  id="blog" class="section_content ">

        <div class="ct-title container">
        	<?php if ( get_theme_mod( 'blog_section_title', $default['title'] ) !== '' ) : ?>
            <h1 class="section_title "><?php echo esc_html( get_theme_mod( 'blog_section_title', $default['title'] ) );  ?></h1>
            <div class="section-title-hr"></div>            
			<?php endif; ?>
			<?php if ( get_theme_mod( 'blog_section_description', $default['description'] ) !== '' ) : ?>
				<p class="section_text"><?php echo esc_html( get_theme_mod( 'blog_section_description', $default['description'] ) ); ?></p>
			<?php endif; ?>
            
        </div>
        
        <div class="ct_post_list container">
            <div class="row">
			    <?php
					$options_categories = array();
					$options_categories_obj = get_categories();
					foreach ($options_categories_obj as $category) {
						$options_categories[$category->cat_name] = $category->cat_ID;
					}

					$options_cat_id = array();
					
					if($options_categories){
						foreach ( $options_categories as $cat_name => $cat ) {
							if( !empty($blog_categories ) ){	
								if ( !in_array($cat_name, $blog_categories) ) { $options_cat_id[]= $cat; }	
							}
						}
					}
					global $wpdb;
					$myosts = new WP_Query();
					if(empty($options_cat_id)){

    					$myosts->query( array( 
						'showposts' => $blog_article_number, 
						'ignore_sticky_posts' => 1,
						
						 )); 

					}else{
						
    					$myosts->query( array( 
						  'showposts' => $blog_article_number, 
						  'ignore_sticky_posts' => 1,
						  'category__in' => $options_cat_id,
						 ));
					}
					 
                    if ( $myosts->have_posts() ) :  while ( $myosts->have_posts() ) : $myosts->the_post();                             
                ?>
                    <div class="col-md-4 ">  
                    
              			<div class="col-md-12 ct_clear_margin_padding ">
                            <div id="post-3420" class="ct_vertical_column ">
                                <div class="ct_post_img">
                                    <a href="<?php the_permalink(); ?>">
                                    <?php
                                            $exclude_id = get_the_ID();
                                            $thumb_array = texas_get_thumbnail($exclude_id);
                                    ?>
                                            <img src="<?php if($thumb_array['fullpath'] !== ''){echo esc_url($thumb_array['fullpath']);}?>" />
                                    
                                        <div class="meta">
                                            <i class="fa fa-search fa-2x" aria-hidden="true"></i>
                                        </div>
                                    </a>
                                </div>
                            </div>
                        </div>


						<div class="col-md-12 ct_post_2_info ct_clear_margin_padding">
                            <div class="ct_post_info">
                                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                <p class="post-meta-2"><i class="fa fa-calendar-times-o" aria-hidden="true"></i> <?php the_date();?>  </p>   
                                <div class="post-content"><a href="<?php the_permalink(); ?>"><?php the_excerpt();?> </a></div>         
                            </div>
                        </div>                    
                    
                    </div>

                <?php endwhile; endif; ?>
                <?php wp_reset_postdata(); ?>
                <p class="clear"></p>                             
				<div class="ct_post_readmore">
					<a class="post_readmore_bttn" href="<?php echo esc_url($blog_url); ?>">
						<?php 
							if ($blog_button_text !== '') { 
								echo esc_html( $blog_button_text );
							} else {
								esc_html_e( 'Read The Blog', 'texas' ); 
							}
						?>
					</a>
				</div>
                
			</div>	
		</div>
	</div>
	<div class="clear"></div>
</section>
