<?php 
	global $redux_demo;
	$catSecTitle = $redux_demo['cat-sec-title'];
	$catSecDesc = $redux_demo['cat-sec-desc'];
	$allCatURL = $redux_demo['all-cat-page-link'];
	$trnsCatVAll = $redux_demo['trns-cat-viewall-btn'];
?>
<!-- Ads Categories -->
<section id="adsCategory">
    <div class="row">
        <div class="mainHeading">
            <div class="large-7 medium-8 large-centered medium-centered columns">
                <h2><?php echo $catSecTitle; ?></h2>
                <p><span class="line"><i class="fa fa-circle"></i></span></p>
                <p><?php echo $catSecDesc; ?></p>
            </div>
        </div>
    </div>
	<?php 
	$argsmaino = array(	
				'order' => 'DESC',
				'hide_empty'               => 0,
				'number'                   => '8',
				'taxonomy'                 => 'category',
				'pad_counts'               => false
			);
	$categories = get_categories($argsmaino);
	$currentCat = 0;
	foreach ($categories as $category) {
				if ($category->category_parent == 0) {
					$currentCat++;
				}
			}
	$argsmain = array(
					'order'                    => 'DESC',
					'hide_empty'               => 0,						
					'number'                   => '8',
					'taxonomy'                 => 'category',
					'pad_counts'               => false 
				);
	$cat_counter = $redux_demo['home-cat-counter'];
	$primaryColor = $redux_demo['color-primary'];
	$categories = get_terms(
				'category', 
				array('hide_empty' => 0,'parent' => 0,'number' => $cat_counter,'order'=> 'ASC')	
					);
	$current = -1;				
	?>
    <div class="row" data-equalizer="cat">
	<?php 
		foreach ($categories as $category) {
			$tag = $category->term_id;
			$tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
			if(isset($tag_extra_fields[$tag])){
					$category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
					$caticoncolor = $tag_extra_fields[$tag]['category_icon_color'];
					$categoryIMG = $tag_extra_fields[$tag]['category_image'];
				}
			$cat = $category->count;
			$catName = $category->term_id;			
			$mainID = $catName;
			if(empty($caticoncolor)){
					$iconColor = $primaryColor;
				}else{
					$iconColor = $caticoncolor;
				}
			if(empty($categoryIMG)){
				$catIMG = get_template_directory_uri().'/images/category.png';
			}else{
				$catIMG = $categoryIMG;
			}	
			$current++;
			$allPosts = 0;
			$categories = get_categories('child_of='.$catName);
			foreach($categories as $category){
						$allPosts += $category->category_count;
					}
			$classieraTotalCount = $cat + $allPosts;
	?>
		<!--Single Box-->
        <div class="large-4 medium-6 columns category-v2 end" data-equalizer-watch="cat">
            <div class="categoryBox-v2">
                <div class="category-v2-img">
                    <img src="<?php echo $catIMG; ?>" alt="category img">
                    <a class="cat-hover" href="<?php echo get_category_link( $mainID ) ?>"></a>
                    <div class="category-v2-icon">                        
						<i style="background-color:<?php echo $iconColor; ?>;" class="<?php $category_icon = stripslashes($category_icon_code); echo $category_icon; ?>"></i>
                    </div>
                </div>
                <div class="category-v2-description">
                    <h4><a href="<?php echo get_category_link( $mainID ) ?>"><?php echo get_cat_name( $catName ); ?></a></h4>
                    <p><?php echo $classieraTotalCount; ?> <?php esc_html_e( 'Ads posted in this category', 'classiera' ); ?></p>
                </div>
            </div>
        </div>
		<!--Single Box-->
		<?php }/*End For Each */?>
    </div>
    <div class="row">
        <div class="loadMore">
            <p><a href="<?php echo $allCatURL; ?>"><i class="fa fa-refresh"></i><?php echo $trnsCatVAll; ?></a></p>
        </div>
    </div>
</section>
<!-- End Ads Categories -->