<?php
/**
 * Template name: Search page
 *
 * @package Multi
 */

?>

<?php
get_header();

if ( have_posts() ) :
	while ( have_posts() ) :
		the_post();
		$multimagazine_post_layout = get_post_meta( get_the_id(), 'multimagazine-post-layout', true );
		if ( empty( $multimagazine_post_layout ) ) {
			$multimagazine_post_layout = get_theme_mod( 'multi_post_layout', MULTIMAGAZINE_POST_LAYOUT );
		}

		if ( 'full-width-header' === $multimagazine_post_layout ) :
			?>
			<header class="post-header">
				<h1 class="post-title"><?php the_title(); ?> <?php edit_post_link( esc_html__( 'Edit this entry', 'multimagazine' ), '', '' ); ?></h1>
				<?php
				$multimagazine_intro = get_post_meta( get_the_id(), 'multi_post_intro', true );
				if ( isset( $multimagazine_intro ) ) :
					?>
					<p class="post-intro"><?php echo esc_html( $multimagazine_intro ); ?></p>
				<?php endif; ?>
			</header>
		<?php endif; ?>

<div class="main single" role="main">
	<article class="page">
		<?php
		if ( 'standard' === $multimagazine_post_layout ) :
			$multimagazine_show_title = multimagazine_title_pos_default();
			if ( 'off' !== $multimagazine_show_title ) :
				?>
				<h1 class="page-title"><?php the_title(); ?> <?php edit_post_link( esc_html__( 'Edit this entry', 'multimagazine' ), '', '' ); ?></h1>
			<?php endif; ?>
		<?php endif; ?>
		<?php
		if ( 'standard' === $multimagazine_post_layout || 'full-width-header' === $multimagazine_post_layout ) :
			$multimagazine_video = get_post_meta( get_the_id(), 'multi_single_meta_video', true );
			if ( $multimagazine_video ) :
				?>
				<div class="video"><?php echo wp_oembed_get( esc_url( $multimagazine_video ) );  // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
				<?php
			else :
				if ( has_post_thumbnail() ) {
					?>
					<p><?php the_post_thumbnail( 'full' ); ?></p>
					<?php
				}
			endif;
			?>
		<?php endif; ?>
		<?php the_content(); ?>
		<div class="in-page-search">
			<?php get_search_form(); ?>
		</div>
		<?php
		wp_link_pages(
			array(
				'before'         => '<p class="pages"><strong>' . esc_html__( 'Pages', 'multimagazine' ) . ':</strong> ',
				'after'          => '</p>',
				'next_or_number' => 'number',
			)
		);
		?>
	</article>

		<?php comments_template(); ?>
</div>
		<?php
	endwhile;
endif;
?>
<?php
$multimagazine_sidebar_position = get_post_meta( $multimagazine_current_page_id, 'multi_sidebar_position', true );
if ( empty( $multimagazine_sidebar_position ) ) {
	$multimagazine_sidebar_position = $multimagazine_sidebar_pos_global;
}
if ( 'off' !== $multimagazine_sidebar_position ) {
	get_sidebar();
}

get_footer();
