<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package uncode
 */

if(!is_null($post))
{
	$page_obj = get_page($post->ID);
}

$current_page_id = '';

/**
*	Get current page id
**/

if(!is_null($post) && isset($page_obj->ID))
{
    $current_page_id = $page_obj->ID;
}

get_header();

$is_standard_wp_post = FALSE;

$search_filter = false;
$state = "";
if(isset($_GET['bystate']) && $_GET['bystate']!=""){
	$state = $_GET['bystate'];
	$search_filter = true;
}


echo '<script type="text/javascript">UNCODE.initHeader();</script>';


	/** Display post html **/
	echo '<div class="page-body">
          <div class="post-wrapper">
          	<div class="post-body">';
?>

<div id="page_content_wrapper">
    <div class="inner">

    	<!-- Begin main content -->
    	<div class="inner_wrapper">

    			<div class="sidebar_content full_width blog_f">

<div class="row-container">
<div class="row row-parent style-light limit-width double-top-padding double-bottom-padding">
<?php /*
<div id="search-wrapper">
	
	
		<form action="" method="get">
			 <select class="drop" id="state01" name="bystate">
				<option value="" >State</option>
				<?php $values = get_field_object('field_579784592f25e');
				if($values)
				{
					foreach($values['choices'] as $k =>$value)
					{
						echo "<option value='$k'";
						if($k==$state){echo " selected ";}
						echo ">" . $value . '</option>';
						
					}
				}
				?>
			 </select>
			<input class="button-red" type="submit" value="Search" />
		</form>
	</div>
	*/
?>

<!-- Begin each blog post -->
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

	<div class="post_wrapper">
	    
	    <div class="post_content_wrapper">
	    
	    	<div class="post_header mixed">
	    	<div class="dtable post-listing">
    
    <div class="dheading">
        <div class="dcell">
            <p>Trail</p>
        </div>
        <div class="dcell">
            <p>State</p>
        </div>        
    </div>
    <?php 
	
	
	$paged = ( get_query_var( 'paged') ) ? absint( get_query_var( 'paged' ) ) : 1; 
	$args = array(
		'numberposts'	=> -1,
		'post_type'		=> 'trails',
		'paged' => $paged,
		'posts_per_page'=>35,
		'orderby'    => 'post_title',
		'order' => 'asc'
	);
	if($search_filter == true) {
		$args['meta_query']	= array(
			'relation'		=> 'and',
		);
		if(!empty($state)) {
			$args['meta_query'][] = array(
				'key'		=> 'state',
				'value'		=> $state,
				'compare'	=> 'LIKE'
			);
		}
	}
	if(!empty($filter_lake_name)) {
		$args['page_id'] = $filter_lake_name;
	}
	 
	
	$lakes = new WP_Query( $args );
	//if (have_posts()) : while (have_posts()) : the_post();
	if ($lakes->have_posts()) : while ($lakes->have_posts()) : $lakes->the_post();
	$TheID = get_the_ID();
	$state= get_post_meta( get_the_ID(),'state');
	?>

    <div class="drow">
        <div class="dcell">
            <p><a href="<?php the_permalink();?>"><?php echo titlechange(get_the_title());?></a></p>
        </div>
        
        <div class="dcell">
            <p class="txt"><?php  
			echo ( ( !empty( $state[0] ) && $state[0]  != 'null' ) ? $state[0] : '' );
			?></p>
        </div>
        
    </div>
    <?php endwhile; endif; ?>
</div>
		
			</div>
			
	    </div>
	    
	</div>

</div>
<br class="clear"/>
<!-- End each blog post -->



	    	<?php /*?><?php 
				if(!isset($paged) OR empty($paged))
				{
					$paged = 1;
				}
			?>
			
	    	<div class="pagination"><div class="pagination_page"><?php echo esc_html($paged); ?></div><?php posts_nav_link(' ', '<i class="fa fa-angle-double-left"></i>'.esc_html__('Newer Posts', 'grandnews' ), esc_html__('Older Posts', 'grandnews' ).'<i class="fa fa-angle-double-right"></i>'); ?></div><?php */?>
    		
			</div>
    		
    	</div>
    <!-- End main content -->
	</div>
</div>
</div>
</div>
</div>

	
<?php

    echo       '</div>
        </div>';

// end of the loop.

get_footer(); ?>
