<?php if(get_theme_mod('social_charity_gallery_enable')):
  $social_charity_gallery_title = get_theme_mod( 'social_charity_gallery_text', __('Our Gallery','social-charity') )
  ?>
  <section class="gallery mgb-lg">
    <div class="container">
      <div class="main-title">
        <h2><?php echo esc_html($social_charity_gallery_title);?></h2>
      </div>
      <div class="portfolioFilter">

        <a href="#" data-filter="*" class="current"><?php esc_html_e( 'All', 'social-charity' );?> </a>
        <?php 
        $social_charity_gallery_category_id = get_theme_mod( 'social_charity_gallery_category_id' );
        $social_charity_args = array('child_of' =>$social_charity_gallery_category_id);
        $social_charity_categories = get_categories( $social_charity_args );
        foreach($social_charity_categories as $social_charity_category):?>
          <a href="#" data-filter=".<?php echo esc_attr($social_charity_category->slug);?>"><?php echo esc_html($social_charity_category->name);?></a>
        <?php endforeach;?>
      </div>
      <div class="portfolioContainer row">
        <?php 
        $social_charity_sub_cats = get_categories('parent=' . $social_charity_gallery_category_id);
        if( $social_charity_sub_cats ) :
          foreach( $social_charity_sub_cats as $social_charity_sub_cat ) :
            $social_charity_sub_query = new WP_Query( array(
              'category__in' => array( $social_charity_sub_cat->term_id ),
              'posts_per_page' => 6)
          );
            if ( $social_charity_sub_query->have_posts() ) :
              while( $social_charity_sub_query->have_posts() ) : $social_charity_sub_query->the_post();
                $social_charity_image_url = get_the_post_thumbnail_url( get_the_ID(),'social-charity-gallery-image' );
                ?>
  
                <div class="col-lg-3 col-sm-6 <?php echo  esc_attr($social_charity_sub_cat->slug);?>">
                  <a href="<?php echo esc_url($social_charity_image_url);?>" data-lightbox="image-2" class="img-holder"><img src="<?php echo esc_url($social_charity_image_url);?>" alt="<?php echo  esc_attr($social_charity_sub_cat->name);?>"></a>
                </div>

              <?php endwhile;
            endif;
          endforeach;
        endif;
         wp_reset_postdata(); 
        ?>
      </div>
    </div>
  </section>
  <?php endif;?>