<?php get_header(); ?>
<main class="corporate">
    <?php include('template/bottom-corporate-construction.php'); ?>
    <div class="c-breadcrumb">
        <div class="c-breadcrumb__inner l-inner">
            <?php
            $terms = get_the_terms($post->ID, 'construction-cat');
            echo '<span property="itemListElement" typeof="ListItem">';
                echo '<a property="item" typeof="WebPage" title="三井住友建設鉄構エンジニアリング株式会社へ移動する" href="'.esc_url(home_url('/')).'" class="home">';
                    echo '<span property="name">ホーム</span>';
                echo '</a>';
                echo '<meta property="position" content="1">';
            echo '</span>';
            echo ' > ';
            echo '<span property="itemListElement" typeof="ListItem">';
                echo '<a property="item" typeof="WebPage" title="施工実績へ移動する" href="'.esc_url(home_url('/construction/')).'" class="archive">';
                    echo '<span property="name">施工実績</span>';
                echo '</a>';
                echo '<meta property="position" content="2">';
            echo '</span>';
            echo ' > ';
            echo '<span property="itemListElement" typeof="ListItem">';
                echo '<a property="item" typeof="WebPage" title="施工実績へ移動する" href="'.esc_url(home_url('/construction-cat/'.$terms[0]->slug.'/')).'" class="archive">';
                    echo '<span property="name">'. $terms[0]->name .'</span>';
                echo '</a>';
                echo '<meta property="position" content="3">';
            echo '</span>';
            echo ' > ';
            echo '<span property="itemListElement" typeof="ListItem">';
                echo '<span property="name" class="post post-post current-item">';
                echo the_title();
                echo '</span>';
                echo '<meta property="url" content="';
                the_permalink();
                echo '">';
                echo '<meta property="position" content="4">';
            echo '</span>';
            ?>
        </div>
    </div>
    <section class="p-post">
        <div class="p-post__container">
            <div class="p-post__inner l-inner l-inner--narrowest">
                <div class="p-post__contents">
                    <div class="p-post__block">
                        <p class="p-post__theme"><?php the_title(); ?></p>
                        <?php if (have_rows('lead')) : ?>
                            <?php while (have_rows('lead')) : the_row(); ?>
                                <h2 class="p-post__title"><?php the_sub_field('lead-title'); ?></h2>
                                <?php
                                $acf_row_image = get_sub_field('lead-img');
                                $url = $acf_row_image['url'];
                                $alt = $acf_row_image['alt'];
                                if ($url) :
                                ?>
                                    <div class="p-post__img">
                                        <img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>">
                                    </div>
                                    <?php if($acf_row_image['caption']) : ?>
                                        <p class="p-post__caption"><?php echo $acf_row_image['caption']; ?></p>
                                    <?php endif; ?>
                                <?php endif; ?>
                            <?php endwhile; ?>
                        <?php endif; ?>
                        <?php if(get_field('theme-text')) : ?>
                            <p class="p-post__text c-text"><?php echo the_field('theme-text'); ?></p>
                        <?php endif; ?>
                        <?php if (have_rows('theme-imgs')) : ?>
                            <div class="p-post__imgs">
                                <?php while (have_rows('theme-imgs')) : the_row(); ?>
                                    <?php
                                    $acf_row_image = get_sub_field('theme-img');
                                    $url = $acf_row_image['url'];
                                    $alt = $acf_row_image['alt'];
                                    if ($url) :
                                    ?>
                                        <div class="p-post__smallImg">
                                            <img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>">
                                            <?php if($acf_row_image['caption']) : ?>
                                                <p class="p-post__caption"><?php echo $acf_row_image['caption']; ?></p>
                                            <?php endif; ?>
                                        </div>
                                    <?php endif; ?>
                                <?php endwhile; ?>
                            </div>
                        <?php endif; ?>
                    </div>
                    <?php if(have_rows('info-block')) : ?>
                        <div class="p-post__block">
                            <p class="p-post__theme">概要</p>
                            <div class="p-post__list">
                                <?php while (have_rows('info-block')) : the_row(); ?>
                                    <div class="p-post__item">
                                        <p class="p-post__itemTheme"><?php echo get_sub_field('info-theme'); ?></p>
                                        <p class="p-post__itemText"><?php echo get_sub_field('info-text'); ?></p>
                                    </div>
                                <?php endwhile; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                    <div class="p-post__link">
                        <?php
                        $terms = get_the_terms($post->ID, 'construction-cat');
                        foreach ( $terms as $term ) {
                            if($term->parent == 0) {
                                echo '<a href="'.esc_url(get_term_link($term)).'" class="c-link c-link--construction">'.$term->name.'実績一覧へ戻る</a>';
                            }
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
        <?php include('template/others.php'); ?>
    </section>
</main>
<?php get_footer();