<?php
$bosa_charity_firm_popular_causesoneID = get_theme_mod( 'bosa_charity_firm_causes_image_one', '' );
$bosa_charity_firm_popular_causescategoryone = get_theme_mod( 'bosa_charity_firm_brand_category_one', '' );

$bosa_charity_firm_popular_causestwoID = get_theme_mod( 'bosa_charity_firm_causes_image_two','');
$bosa_charity_firm_popular_causescategorytwo = get_theme_mod( 'bosa_charity_firm_brand_category_two', '' );

$bosa_charity_firm_popular_causesthreeID = get_theme_mod( 'bosa_charity_firm_causes_image_three', '' );
$bosa_charity_firm_popular_causescategorythree = get_theme_mod( 'bosa_charity_firm_brand_category_three', '' );

$bosa_charity_firm_popular_causesfourID = get_theme_mod( 'bosa_charity_firm_causes_image_four', '' );
$bosa_charity_firm_popular_causescategoryfour = get_theme_mod( 'bosa_charity_firm_brand_category_four', '' );

$bosa_charity_firm_popular_causesfiveID = get_theme_mod( 'bosa_charity_firm_causes_image_five', '' );
$bosa_charity_firm_popular_causescategoryfive = get_theme_mod( 'bosa_charity_firm_brand_category_five', '' );

$bosa_charity_firm_popular_causessixID = get_theme_mod( 'bosa_charity_firm_causes_image_six', '' );
$bosa_charity_firm_popular_causescategorysix = get_theme_mod( 'bosa_charity_firm_brand_category_six', '' );


$bosa_charity_firm_popular_cause_array = array();
$bosa_charity_firm_has_brands = false;
if( !empty( $bosa_charity_firm_popular_causesoneID ) || !empty( $bosa_charity_firm_popular_causescategoryone ) ){
	$bosa_charity_firm_popular_cause_one  = wp_get_attachment_image_src( $bosa_charity_firm_popular_causesoneID ,'bosa-charity-firm-420-300');
 	if ( is_array(  $bosa_charity_firm_popular_cause_one ) ){
 		$bosa_charity_firm_has_brands = true;
   	 	$bosa_charity_firm_popular_causes_one = $bosa_charity_firm_popular_cause_one[0];
   	 	$bosa_charity_firm_popular_cause_array['image_one'] ['ID'] = $bosa_charity_firm_popular_causes_one;	 	
  	}
  	if ( !empty($bosa_charity_firm_popular_causescategoryone) ){
 		$bosa_charity_firm_has_brands = true;
   	 	$bosa_charity_firm_popular_cause_array['image_one']['category'] = $bosa_charity_firm_popular_causescategoryone;	
  	}
}
if( !empty( $bosa_charity_firm_popular_causestwoID ) || !empty( $bosa_charity_firm_popular_causescategorytwo ) ){
	$bosa_charity_firm_popular_cause_two = wp_get_attachment_image_src( $bosa_charity_firm_popular_causestwoID,'bosa-charity-firm-420-300');
	if ( is_array(  $bosa_charity_firm_popular_cause_two ) ){
		$bosa_charity_firm_has_brands = true;	
        $bosa_charity_firm_popular_causes_two = $bosa_charity_firm_popular_cause_two[0];
        $bosa_charity_firm_popular_cause_array['image_two'] ['ID']= $bosa_charity_firm_popular_causes_two; 
	}
	if ( !empty($bosa_charity_firm_popular_causescategorytwo) ){
		$bosa_charity_firm_has_brands = true;
	 	$bosa_charity_firm_popular_cause_array['image_two']['category'] = $bosa_charity_firm_popular_causescategorytwo;	
  	}
}
if( !empty( $bosa_charity_firm_popular_causesthreeID ) || !empty( $bosa_charity_firm_popular_causescategorythree ) ){	
	$bosa_charity_firm_popular_cause_three = wp_get_attachment_image_src( $bosa_charity_firm_popular_causesthreeID,'bosa-charity-firm-420-300');
	if ( is_array(  $bosa_charity_firm_popular_cause_three ) ){
		$bosa_charity_firm_has_brands = true;
      	$bosa_charity_firm_popular_causes_three = $bosa_charity_firm_popular_cause_three[0];
      	$bosa_charity_firm_popular_cause_array['image_three'] ['ID']= $bosa_charity_firm_popular_causes_three;		
  	}
  	if ( !empty($bosa_charity_firm_popular_causescategorythree) ){
		$bosa_charity_firm_has_brands = true;
	 	$bosa_charity_firm_popular_cause_array['image_three'] ['category'] = $bosa_charity_firm_popular_causescategorythree;	
  	}
}
if( !empty( $bosa_charity_firm_popular_causesfourID ) || !empty( $bosa_charity_firm_popular_causescategoryfour ) ){	
	$bosa_charity_firm_popular_cause_four = wp_get_attachment_image_src( $bosa_charity_firm_popular_causesfourID,'bosa-charity-firm-420-300');
	if ( is_array(  $bosa_charity_firm_popular_cause_four ) ){
		$bosa_charity_firm_has_brands = true;
      	$bosa_charity_firm_popular_causes_four = $bosa_charity_firm_popular_cause_four[0];
      	$bosa_charity_firm_popular_cause_array['image_four'] ['ID'] = $bosa_charity_firm_popular_causes_four;	
  	}
  	if ( !empty($bosa_charity_firm_popular_causescategoryfour) ){
		$bosa_charity_firm_has_brands = true;
	 	$bosa_charity_firm_popular_cause_array['image_four'] ['category'] = $bosa_charity_firm_popular_causescategoryfour;	
  	}
}
if( !empty( $bosa_charity_firm_popular_causesfiveID ) || !empty( $bosa_charity_firm_popular_causescategoryfive ) ){	
	$bosa_charity_firm_popular_cause_five = wp_get_attachment_image_src( $bosa_charity_firm_popular_causesfiveID,'bosa-charity-firm-420-300');
	if ( is_array(  $bosa_charity_firm_popular_cause_five ) ){
		$bosa_charity_firm_has_brands = true;
      	$bosa_charity_firm_popular_causes_five = $bosa_charity_firm_popular_cause_five[0];
      	$bosa_charity_firm_popular_cause_array['image_five'] ['ID'] = $bosa_charity_firm_popular_causes_five;	
  	}
  	if ( !empty($bosa_charity_firm_popular_causescategoryfive) ){
		$bosa_charity_firm_has_brands = true;
	 	$bosa_charity_firm_popular_cause_array['image_five'] ['category'] = $bosa_charity_firm_popular_causescategoryfive;	
  	}
}
if( !empty( $bosa_charity_firm_popular_causessixID ) || !empty( $bosa_charity_firm_popular_causescategorysix ) ){	
	$bosa_charity_firm_popular_cause_six = wp_get_attachment_image_src( $bosa_charity_firm_popular_causessixID,'bosa-charity-firm-420-300');
	if ( is_array(  $bosa_charity_firm_popular_cause_six ) ){
		$bosa_charity_firm_has_brands = true;
      	$bosa_charity_firm_popular_causes_six = $bosa_charity_firm_popular_cause_six[0];
      	$bosa_charity_firm_popular_cause_array['image_six'] ['ID'] = $bosa_charity_firm_popular_causes_six;	
  	}
  	if ( !empty($bosa_charity_firm_popular_causescategorysix) ){
		$bosa_charity_firm_has_brands = true;
	 	$bosa_charity_firm_popular_cause_array['image_six'] ['category'] = $bosa_charity_firm_popular_causescategorysix;	
  	}
}

$bosa_charity_firm_product_cat = bosa_charity_firm_get_post_categories();

if( !get_theme_mod( 'bosa_charity_firm_disable_popular_causes_section', true ) && ( $bosa_charity_firm_has_brands || get_theme_mod('bosa_charity_firm_popular_causes_title') || get_theme_mod('bosa_charity_firm_popular_causes_sub_title') ) ){ ?>
	<section class="section-popular-cause-area">
		<?php if( get_theme_mod('bosa_charity_firm_popular_causes_title') || get_theme_mod('bosa_charity_firm_popular_causes_sub_title') ){ ?>
			<div class="section-title-wrap col-lg-6 col-md-8 offset-lg-3 offset-md-2">
				<h2 class="cause-section-title">	
					<?php echo esc_html( get_theme_mod('bosa_charity_firm_popular_causes_title') ); ?>
				</h2>
				<p>
					<?php echo esc_html( get_theme_mod('bosa_charity_firm_popular_causes_sub_title') ); ?>
				</p>
			</div>
		<?php } ?>
		<div class="content-wrap">
			<?php foreach( $bosa_charity_firm_popular_cause_array as $bosa_charity_firm_each_popular_causes ){ ?>
				<article class="leading-items">
					<?php if ( isset( $bosa_charity_firm_each_popular_causes['ID'] )  && !empty( $bosa_charity_firm_each_popular_causes['ID'] ) ){ 
							$bosa_charity_firm_cat_url = '';
							if( isset( $bosa_charity_firm_each_popular_causes['category'] ) && !empty( $bosa_charity_firm_each_popular_causes['category'] ) ) {
								$bosa_charity_firm_cat_url = $bosa_charity_firm_each_popular_causes['category'];
							}
						?>
						<figure class= "featured-image">
							<a href="<?php echo esc_url( get_category_link( $bosa_charity_firm_cat_url ) ); ?>">
								<img src="<?php echo esc_url( $bosa_charity_firm_each_popular_causes['ID'] ); ?>">
							</a>	
						</figure>
					<?php } ?>
					<?php if ( isset( $bosa_charity_firm_each_popular_causes['category'] ) && !empty( $bosa_charity_firm_each_popular_causes['category'] ) ){ ?>
						<h5 class="entry-title">
							<a href="<?php echo esc_url( get_category_link( $bosa_charity_firm_each_popular_causes ['category'] ) ); ?>">
								<?php echo esc_html($bosa_charity_firm_product_cat[$bosa_charity_firm_each_popular_causes['category'] ] ); ?>
							</a>	
						</h5>
					<?php } ?>
				</article>	
			<?php } ?>
		</div>
	</section>
<?php } 

