<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Kanews
 */
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
get_header();

	$custom_widgets = get_option( 'kanews_page_sidebars_widgets', array() );
	$get_custom_widgets = kanews_get_option( 'page-builder', '');
	while ( have_posts() ) : the_post();
		kanews_page_header($post->ID); 
		do_action('kanews_header_ad');
		if( ! empty( $get_custom_widgets ) && in_array( $post->ID, $get_custom_widgets ) ){ ?>
			<main id="main" class="site-main"><div class="container"><div class="row">
				<?php $insights = get_post_meta( $post->ID, 'post_insight', true ) == 1 ? 1 : 0; if(kanews_insights_control() == true || $insights == 0 ): ?>
					<?php do_action('kanews_page_builder_custom'); ?>
				<?php else: ?>
					<div class="col-12"><?php echo kanews_private_content('a'); ?></div>
				<?php endif; ?>
			</div></div></main>
		<?php } 
		elseif( empty( $get_custom_widgets ) && isset($custom_widgets [$post->ID]) ) {
			?>
			<main id="main" class="site-main"><div class="container"><div class="row">
				<?php $insights = get_post_meta( $post->ID, 'post_insight', true ) == 1 ? 1 : 0; if(kanews_insights_control() == true || $insights == 0 ): ?>
					<?php do_action('kanews_page_builder_custom'); ?>
				<?php else: ?>
					<div class="col-12"><?php echo kanews_private_content('a'); ?></div>
				<?php endif; ?>
			</div></div></main>
			<?php
		}
		else {

			if ( class_exists( 'WooCommerce' ) ) {
				echo '<main id="main" class="site-main"><div class="container"><div class="row">';
				if ( is_cart() || is_checkout() )
					get_template_part( 'woocommerce/page');
					else
					get_template_part( 'template-parts/content/content', 'page');
				echo '</div></div></main>';
			} else {
				echo '<main id="main" class="site-main"><div class="container"><div class="row">';
					get_template_part( 'template-parts/content/content', 'page');
				echo '</div></div></main>';
			}

		}
	endwhile;

get_footer();