<?php
if (!defined('ABSPATH')) {
    exit;
}
$posts_query = array();
 $post_types = get_option('chama_display_post_types') ? get_option('chama_display_post_types'): array() ;
 if( $post_types){
    $post_args = array(
        'post_type'   =>  $post_types,
        'post_status' => 'publish',
        'posts_per_page' => '3',
    );
    $posts_query = new WP_Query($post_args);
 }


?>
 
<?php
if ($posts_query && $posts_query->have_posts()):
?>
	    <div class="chama-card chama-latest-posts right-col" >

				            <div class="chama-card-body">
                            <h4 class="chama-item-title">Latest Posts</h4>
<?php
    while ( $posts_query->have_posts() ) : $posts_query->the_post() ;
   $permalink = get_the_permalink();
   $title = get_the_title();
   $thumbnail = '';
   if (has_post_thumbnail()) {
    $thumbnail = get_the_post_thumbnail_url();
} else {
    $thumbnail = CHAMA_ASSETS_URL . 'img/no-image.jpg';
}
        ?>
					<div class="chama-post">
                        <a href="<?php echo esc_url($permalink); ?>">
                            <div class="chama-rounded chama-post-thumbnail" style="background-image:url(<?php echo esc_url($thumbnail) ?>);"></div>
                       
     </a>
    <div class="chama-post-title">
<a href="<?php echo esc_url($permalink); ?>" title="<?php echo esc_attr($title); ?>">
    <?php 
    echo esc_html($title);
    ?>
</a>
<div class="chama-post-date"><?php echo esc_html( get_the_date() );  ?></div>
    </div>
                       
                    </div>	    
                            
         
        <?php
endwhile;
?>
    </div>
    </div>
<?php
$posts_query = null;
wp_reset_postdata();
endif;
?>





