<?php
/*
Template name: All Companies
*/
get_header();
?>

<div id="post-<?php the_ID(); ?>" <?php post_class('page-wrapper'); ?>>
	
	<?php
	$args = array(
		'hide_empty'  => false
		); 
	$terms = get_terms( 'deal_company', $args );
	if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) : ?>


	<div class="container">
	
		<div class="row">

			<?php if ( fw_ssd_get_option('all-shops-sidebar-switch') ) : ?>
				<div class="col-sm-8 col-md-9 <?php echo fw_ssd_get_option('sidebar-switch') == 'left' ? 'col-sm-push-4 col-md-push-3' : '' ?>">
			<?php else : ?>
				<div class="col-sm-12">
			<?php endif; ?>
			
				<div class="section-title-block">
					<h1 class="section-title"><?php the_title(); ?></h1>
					<?php 
					if ( function_exists('fw_ext_breadcrumbs') ) {
						fw_ext_breadcrumbs( '>' );
					}
					?>
				</div><!-- end section-title-block -->

				<div class="all-shops-wrapper">

					<?php
					$last_letter = '';
					foreach ( $terms as $term ) :
						?>
						<?php
						$company_name = $term->name;
						$first_letter = strtoupper(substr($company_name, 0, 1));
						if ( $first_letter != $last_letter && $last_letter != '' ) :?>
							</div><!-- end all-shops-section -->
						<?php
						endif;
						if ( $first_letter != $last_letter ) :?>
						<div class="all-shops-section">
						<h2 class="header-separator"><?php echo wp_kses_post($first_letter); ?></h2>
						<?php
						endif;
						?>
						<h5><a href="<?php echo get_term_link( $term->slug, 'deal_company' ); ?>"><?php echo wp_kses_post($term->name); ?></a></h5>
						<?php
						$last_letter = $first_letter;
						?>
					<?php
					endforeach;

					if ( $last_letter != '' ) :?>
						</div><!-- end all-shops-section -->
					<?php
					endif;

					?>

				</div><!-- end all-shops-wrapper -->

			</div><!-- end col-sm-8 col-md-9 -->

			<?php
			if ( fw_ssd_get_option('all-shops-sidebar-switch') ) {
				get_sidebar(); 
			}
			?>

		</div><!-- end rows cols-np -->

	</div><!-- end container-fluid -->

	<?php endif; ?>

</div><!-- end post-id -->


<?php
get_footer();
?>