<?php
/**
 * Template Name: Page Left Sidebar
 * The main template file for display page.
 *
 * @package WordPress
*/

get_template_part("lib/fallback.home.lib");

/**
*	Get Current page object
**/
$page = get_page($post->ID);

/**
*	Get current page id
**/
if(!isset($current_page_id) && isset($page->ID))
{
    $current_page_id = $page->ID;
}

//Get page Sidebar
$page_sidebar = get_post_meta($current_page_id, 'page_sidebar', true);
if(empty($page_sidebar))
{
	$page_sidebar = 'Page Sidebar';
}

if(!isset($hide_header) OR !$hide_header)
{
	get_header(); 
}

if(!isset($hide_header) OR !$hide_header)
{
?>	
</div>

<?php
	if(has_post_thumbnail($current_page_id, 'full'))
    {
        $image_id = get_post_thumbnail_id($current_page_id); 
        $image_thumb = wp_get_attachment_image_src($image_id, 'full', true);
        $pp_page_bg = $image_thumb[0];
?>
<style>
.page_caption { background: #f9f9f9 url('<?php echo $pp_page_bg; ?>') center center no-repeat; background-size: cover; }
</style>
<?php
	}
?>

<?php
if(!is_front_page())
{
?>
<div class="page_caption">
	<div class="caption_inner">
		<div class="caption_header">
			<h1 <?php if(!empty($pp_page_bg)) { ?>class="withbg"<?php } ?>><span><?php the_title(); ?></span></h1>
			<?php
			$page_description = get_post_meta($current_page_id, 'page_description', true);
			
			if(!empty($page_description))
			{
			?>
			    <div class="page_description<?php if(!empty($pp_page_bg)) { ?> withbg<?php } ?>"><?php echo $page_description; ?></div>
			<?php
			}
			?>
		</div>
	</div>
	
	<hr class="hr_page_caption"/>
</div>
<br class="clear"/>

<!-- Begin content -->
<div id="content_wrapper">

    <div class="inner">
    
    	<!-- Begin main content -->
    	<div class="inner_wrapper">
    	
    	<div class="standard_wrapper">
<?php
}

} //End is not front page
?>

			<div class="sidebar_wrapper left_sidebar">
			
			    <div class="sidebar_top left_sidebar"></div>
			
			    <div class="sidebar left_sidebar">
			    
			    	<div class="content">
			    
			    		<ul class="sidebar_widget">
			    		<?php dynamic_sidebar($page_sidebar); ?>
			    		</ul>
			    	
			    	</div>
			
			    </div>
			
			    <div class="sidebar_bottom left_sidebar"></div>
				<br class="clear"/>
			</div>
					
			<div class="sidebar_content left_sidebar">
					
				<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>		
					
					<?php do_shortcode(the_content()); break;  ?>

				<?php endwhile; ?>
				<br class="clear"/>
					
			</div>
				
		</div>
	</div>
	<!-- End main content -->
	<br class="clear"/>
				
</div>
			
<?php 
if(!isset($hide_header) OR !$hide_header OR is_null($hide_header))
{
?>			

<?php get_footer(); ?>

<?php
}
?>