<?php 
    $categories_choose = array();
    if (!empty($settings['posts_categories'])){
        $categories_choose = $settings['posts_categories']; 
    } 
?>
<?php if ($settings['show_button'] == 'yes' && !empty( $settings['button_text'] )): ?>
        <a href="<?php //echo get_the_permalink(); ?>" class="tf-portfolio-btn"><?php esc_html_e($settings['button_text'],'norstar'); ?></a>
    <?php endif; ?>

<?php if ($settings['show_filter'] == 'yes'): ?>
    <div class="tabs">
            <button type="button" class="filter-btn active" data-filter="*">All</button>
            <?php if (!empty($settings['posts_categories'])): ?>
                <?php foreach ($categories_choose as $key => $category) : ?>
                    <?php $category_name = str_replace('-', ' ', $category); ?>
                    <button type="button" class="filter-btn" data-filter="<?php echo esc_attr('.'.$category); ?>"><?php esc_html_e($category_name,'norstar'); ?></button>
                <?php endforeach; ?>    
            <?php else: ?>
                <?php $categories_choose = get_terms('portfolios_category'); ?>
                <?php foreach ($categories_choose as $key => $category) : ?>
                    <button type="button" class="filter-btn" data-filter="<?php echo esc_attr('.'.$category->slug); ?>"><?php esc_html_e($category->name,'norstar'); ?></button>
                <?php endforeach; ?>  
            <?php endif; ?>
    </div>
<?php endif; ?>

<div class="grid portfolios">
    
    <?php while ($query->have_posts()) : $query->the_post(); ?>
        <?php
            $post_categories = wp_get_post_terms(get_the_ID(), 'portfolios_category', array('fields' => 'slugs'));
            $category_classes = implode(' ', $post_categories);
        ?>
            <div class="grid-item item filter <?php echo esc_attr($category_classes); ?>">                
                <?php if (has_post_thumbnail()) : ?>
                    <div class="feature_portfolio_post featured-post">
                        <a href="<?php echo esc_attr(get_the_permalink()); ?>">
                            <?php echo sprintf('<img src="%s" alt="image">', \Elementor\Group_Control_Image_Size::get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail', $settings)); ?>
                        </a>
                        <a href="<?php echo get_the_permalink(); ?>" class="tf-portfolio-btn"><?php esc_html_e($settings['button_text'],'norstar'); ?></a>
                    </div>
                <?php endif; ?>
                <div class="content">
                    <h4>
                        <a href="<?php echo esc_attr(get_the_permalink()); ?>" class="title"><?php esc_html_e(get_the_title(), 'norstar'); ?></a>
                    </h4>
                </div>
            </div>
    <?php endwhile; ?>
</div>
