<?php
    $nb_page_heading = nimbus_meta_data('hidden_heading');
    $nb_page_layout = nimbus_meta_data('radio_sidebar_layout') ? nimbus_meta_data('radio_sidebar_layout') : nimbus_option_data('select_page_layout');
    $nb_page_comment = nimbus_option_data('switch_comment_page');
    $nb_page_container = nimbus_meta_data('full_content') ? 'nb-container-full' : 'nb-container';
    $nb_page_padding = nimbus_meta_data('full_content') ? 'nb-normal-padding' : 'nb-large-padding';
    $nb_content_width = $nb_page_layout == 'nb-fullwidth' ? 12 : 8;
    get_header();
    if ( !$nb_page_heading ) get_template_part('template_part/site/heading');

    // relate query
    $nb_portfolio_args = array(
        'post_type'         => 'portfolio',
        'posts_per_page'    => 2,
        'post_status'       => 'publish',
        'post__not_in'      => array(get_the_id())
    );
    $nb_portfolio_query = new WP_Query($nb_portfolio_args);
?>
<div class="<?php echo esc_attr( $nb_page_padding );?> nb-section">
    <div class="<?php echo esc_attr( $nb_page_container );?>">
        <div class="nb-row <?php echo esc_attr($nb_page_layout);?>">
            <div id="content" class="nb-col-md-<?php echo esc_attr( $nb_content_width );?>">
                <?php
                    while ( have_posts() ) : the_post();
                        get_template_part( 'template_part/content/portfolio-detail' );
                        if ( comments_open() || get_comments_number() ) {
                            comments_template();
                        }
                    endwhile;
                ?>
            </div>
            <?php if ( $nb_page_layout != 'fullwidth' ) get_sidebar('portfolio'); ?>
        </div>
        <?php if ( $nb_portfolio_query->have_posts() ): $nb_count = 0; ?>
        <nav class="navigation post-navigation" role="navigation">
            <h2 class="screen-reader-text">Portfolio navigation</h2>
            <div class="nav-links">
                <?php
                    while ( $nb_portfolio_query->have_posts() ) : $nb_portfolio_query->the_post(); ;
                    if ( $nb_count++ == 0 ) {
                        $title_a = esc_attr__('Previous','nimbus' );
                        $title_b = esc_attr__('prev','nimbus' );
                    } else {
                        $title_a = esc_attr__('Next','nimbus' );
                        $title_b = esc_attr__('next','nimbus' );
                    }
                ?>
                <div class="nav-<?php echo strtolower( $title_a );?>">
                    <a href="<?php the_permalink();?>" rel="<?php echo esc_attr( $title_b );?>">
                        <span class="meta-nav" aria-hidden="true"><?php echo esc_attr( $title_a );?></span>
                        <span class="screen-reader-text"><?php echo esc_attr( $title_a. ' '.esc_attr__( 'post:','nimbus' ) );?></span>
                        <span class="post-title"><?php the_title();?></span>
                    </a>
                </div>
                <?php endwhile; wp_reset_postdata(); ?>
            </div>
        </nav>
        <?php endif; ?>
    </div>
</div>
<?php get_footer();?>