<?php
/**
 * @copyright	Copyright (c) 2016 AmyTheme (http://www.amytheme.com). All rights reserved.
 * @license		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

defined( 'ABSPATH' ) or die;

?>

<aside id="sidebar">
	<?php
	if ( (is_page()) && ! empty( $post ) ) {
		$post_meta		= get_post_meta( $post->ID, '_sidebar', true );
		$post_widget	= ( ! empty( $post_meta['page_sidebar_widget'] )) ? $post_meta['page_sidebar_widget'] : '';
	} else if ( is_tax( 'amy_genre' ) ) {
		$queried_object = get_queried_object();
		$term_id 		= $queried_object->term_id;
		$term 			= get_term( $term_id, 'amy_genre' );
		$term_data 		= get_term_meta( $term_id, '_genre_options', true );

		$post_widget 	= (isset( $term_data['genre_sidebar'] ) && $term_data['genre_sidebar'] != 'global') ? $term_data['genre_widget'] : amy_get_option( 'genre_widget' );
	} else if ( is_singular( 'amy_movie' ) ) {
		$post_meta		= get_post_meta( $post->ID, '_movie_sidebar', true );
		$post_widget	= ( ! empty( $post_meta['movie_sidebar_widget'] )) ? $post_meta['movie_sidebar_widget'] : '';
	} else {
		$post_widget	= amy_get_option( 'blog_widget', 'rightbar' );
	}

	$post_widget	= ( ! empty( $post_widget )) ? $post_widget : '';

	dynamic_sidebar( $post_widget );
	?>
</aside>
