<?php
/*
 * The template for displaying all pages.
 * Author & Copyright: themexshaper
 * URL: http://themeforest.net/user/themexshaper
 */
$confin_id    = ( isset( $post ) ) ? $post->ID : 0;
$confin_id    = ( is_home() ) ? get_option( 'page_for_posts' ) : $confin_id;
$confin_meta  = get_post_meta( $confin_id, 'page_type_metabox', true );
if ( $confin_meta ) {
	$confin_content_padding = $confin_meta['content_spacings'];
} else { $confin_content_padding = 'section-padding'; }
// Top and Bottom Padding
if ( $confin_content_padding && $confin_content_padding !== 'padding-default' ) {
	$confin_content_top_spacings = isset( $confin_meta['content_top_spacings'] ) ? $confin_meta['content_top_spacings'] : '';
	$confin_content_bottom_spacings = isset( $confin_meta['content_bottom_spacings'] ) ? $confin_meta['content_bottom_spacings'] : '';
	if ( $confin_content_padding === 'padding-custom' ) {
		$confin_content_top_spacings = $confin_content_top_spacings ? 'padding-top:'. confin_check_px( $confin_content_top_spacings ) .';' : '';
		$confin_content_bottom_spacings = $confin_content_bottom_spacings ? 'padding-bottom:'. confin_check_px($confin_content_bottom_spacings) .';' : '';
		$confin_custom_padding = $confin_content_top_spacings . $confin_content_bottom_spacings;
	} else {
		$confin_custom_padding = '';
	}
	$padding_class = '';
} else {
	$confin_custom_padding = '';
	$padding_class = '';
}
// Page Layout
$page_layout_options = get_post_meta( get_the_ID(), 'page_layout_options', true );
if ( $page_layout_options ) {
	$confin_page_layout = $page_layout_options['page_layout'];
	$page_sidebar_widget = $page_layout_options['page_sidebar_widget'];
} else {
	$confin_page_layout = 'right-sidebar';
	$page_sidebar_widget = '';
}
$page_sidebar_widget = $page_sidebar_widget ? $page_sidebar_widget : 'sidebar-1';
if ( $confin_page_layout === 'extra-width' ) {
	$confin_page_column = 'extra-width';
	$confin_page_container = 'container-fluid';
} elseif ( $confin_page_layout === 'full-width' ) {
	$confin_page_column = 'col-md-12';
	$confin_page_container = 'container ';
} elseif( ( $confin_page_layout === 'left-sidebar' || $confin_page_layout === 'right-sidebar' ) && is_active_sidebar( $page_sidebar_widget ) ) {
	if( $confin_page_layout === 'left-sidebar' ){
		$confin_page_column = 'col-md-8 order-12';
	} else {
		$confin_page_column = 'col-md-8';
	}
	$confin_page_container = 'container ';
} else {
	$confin_page_column = 'col-md-12';
	$confin_page_container = 'container ';
}
$confin_theme_page_comments = cs_get_option( 'theme_page_comments' );
get_header();
?>
<div class="page-wrap <?php echo esc_attr( $padding_class ); ?>">
	<div class="<?php echo esc_attr( $confin_page_container.''.$confin_content_padding.' '.$confin_page_layout ); ?>" style="<?php echo esc_attr( $confin_custom_padding ); ?>">
		<div class="row">
			<div class="<?php echo esc_attr( $confin_page_column ); ?>">
				<div class="page-wraper clearfix">
				<?php
				while ( have_posts() ) : the_post();
					the_content();
					confin_paging_nav();
					if ( !$confin_theme_page_comments && ( comments_open() || get_comments_number() ) ) :
						comments_template();
					endif;
				endwhile; // End of the loop.
				?>
				</div>
				<div class="page-link-wrap">
					<?php confin_wp_link_pages(); ?>
				</div>
			</div>
			<?php
			// Sidebar
			if( ($confin_page_layout === 'left-sidebar' || $confin_page_layout === 'right-sidebar') && is_active_sidebar( $page_sidebar_widget )  ) {
				get_sidebar();
			}
			?>
		</div>
	</div>
</div>
<?php
get_footer();