<?php
	get_header();
?>			
	<div class="container">
		<div class="row">
			<div class="content col-xs-12 col-md-12 col-lg-12">
				<div class="loop_content">
						<?php 
						$categories = get_terms('categories_blog');
						foreach ($categories as $categori) {?>
							<?php if($categori->parent == 0){?>
							<?php $childs = array(0=>$categori->term_id);?>
							<?php foreach ($categories as $chil){ 
								if($chil->parent == $categori->term_id){
									$childs[] = $chil->term_id; 
						}}?>
						<div class="post_loop row">
						<div class="post_title"> <a href="/<?=$categori->taxonomy ?>/<?=$categori->slug ?>"><?=$categori->name ?></a></div>
							<?php 
							$args = array(
								'posts_per_page' => 6,
								'orderby' => 'comment_count',
								'post_type' => 'blog',
								'orderby' => 'ASC',
								'tax_query' => array(
					               array(
					                 'taxonomy' => 'categories_blog',
					                 'field' => 'id',
					                 'terms' => $childs,
					                 'orderby' => 'ASC', 
					                 'include_children' => true
					               )
					             )
							);

							$query = new WP_Query( $args );

							if ( $query->have_posts() ) {
								while ( $query->have_posts() ) {
									$query->the_post();?>

									<div class="content_post col-xs-12 col-md-6 col-lg-4">	
						<div class="post_top">	
							<div class="thumbnail_post">
								<a href="<?php the_permalink(); ?>">
									<?php the_post_thumbnail(); ?>
								</a>
							</div>	
								<div class="expert_title">	
									<a href="<?php the_permalink(); ?>">
										<h2><?php title_chars(40, '...'); ?></h2>
									</a>
									<div class="expert">
										<?php the_truncated_post( 165 ); ?>
									</div>
								</div>
						</div>			
					</div>
					<?php 
								}
							} else {
								// Постов не найдено
							}
							wp_reset_postdata();?>
							</div>
					<?php 
						}}?>
					
				</div>	
			</div>						
		<div class="col-xs-12 col-md-6 col-lg-6">							<!-- Объявления -->
			<div class="loop_content">
				<div class="post_obyavleniya">
						<div class="title_obyavleniya">Объявления</div>
							<?php 
							$args = array(
								'posts_per_page' => 10,
								'orderby' => 'ASC',
								'post_type' => 'obyavleniya',
							);

							$query = new WP_Query( $args );

							if ( $query->have_posts() ) {
								while ( $query->have_posts() ) {
									$query->the_post();?>

									<div class="content_post">	
						<div class="post_top">	
							<div class="thumbnail_post">
								<a href="<?php the_permalink(); ?>">
									<?php the_post_thumbnail(); ?>
								</a>
							</div>	
								<div class="expert_titleobya">	
									<a href="<?php the_permalink(); ?>">
										<h2><?php title_chars(69, '...'); ?></h2>
									</a>
								</div>
						</div>			
					</div>
					<?php 
								}
							} else {
								// Постов не найдено
								echo '<p class="noposts">Рубрика в стадии наполнения!</p>';
							}
							wp_reset_postdata();?>
							<div class="morelink"><a href="<?php echo home_url('/obyavleniya'); ?>">Посмотреть все</a></div>
						</div>	
				</div>		
			</div>
										<!-- конец Объявления -->

										<!-- Говорим по Польськи -->
		<div class="col-xs-12 col-md-6 col-lg-6">										
			<div class="loop_content">
				<div class="posttop_language">
						<div class="title_obyavleniya">Говорим по Польськи</div>
							<?php 
							$args = array(
								'posts_per_page' => 1,
								'post_type' => 'language',
								'orderby' => 'rand',
							);

							$query = new WP_Query( $args );

							if ( $query->have_posts() ) {
								while ( $query->have_posts() ) {
									$query->the_post();?>

									<div class="content_post">	
										<div class="post_language">
											<h2><?php the_title(); ?></h2>
												<?php the_content();?>
										</div>
									</div>			
							<?php 
								}
							} else {
								// Постов не найдено
								echo '<p class="noposts">Рубрика в стадии наполнения!</p>';
							}
							wp_reset_postdata();?>
						<div class="morelink"><a href="<?php echo home_url('/language'); ?>">Посмотреть все</a></div>
					</div>	
				</div>			
			</div>
		</div>		
	</div>
										<!-- конец Говорим по Польськи -->				
<?php
	get_footer();
?>