<section class="blog_detail">
    <div class="blog_content">
        <h2 class="title"><?php the_title(); ?></h2>
        <ul class="blog_tag">
            <li>
                <div class="media">
                    <div class="media-left">
                        <img src="<?= get_template_directory_uri(); ?>/img/calendar.png" alt="calendar"/>
                    </div>
                    <div class="media-body">
                        <span><?php the_date(); ?></span>
                    </div>
                </div>
            </li>
            <li>
                <div class="media">
                    <div class="media-left">
                        <img src="<?= get_template_directory_uri(); ?>/img/folder.png" alt="folder"/>
                    </div>
                    <div class="media-body">
                        <span><?php
                            $category_count = 0;
                            $category_detail = get_the_category();//$post->ID
                            $categoryItems = count($category_detail);
                            foreach($category_detail as $cd){
                                print_r($cd);
                                $category_count++;
                                echo $cd->cat_name; ?><?php if($category_count != $categoryItems) { echo ", "; }
                            }
                            ?></span>
                    </div>
                </div>
            </li>
            <li>
                <div class="media">
                    <?php
                    $tags = get_the_tags();
                    if (!empty($tags)) : ?>
                    <div class="media-left">
                        <img src="<?= get_template_directory_uri(); ?>/img/tag-blue.png" alt="tag-blue"/>
                    </div>
                    <div class="media-body">
                        <span>
                        <?php
                        $tagsCount = 0;
                        $numItems = count($tags);
                        foreach ( $tags as $tag ) { $tagsCount++;
                            $tag_link = get_tag_link( $tag->term_id ); ?>
                            <?php echo $tag->name; ?><?php if(++$i != $numItems) { echo ","; } ?>

                            <?php
                        }
                        ?></span>
                    </div>
                    <?php endif; ?>
                </div>
            </li>
        </ul>
        <div class="media user_info">
            <div class="media-left">
                <?php
                $get_author_id = get_the_author_meta('ID');
                $get_author_gravatar = get_avatar_url($get_author_id, array('size' => 450));
                echo '<img src="'.$get_author_gravatar.'" alt="'.get_the_title().'" />';
                ?>
            </div>
            <div class="media-body">
                <h4><?php echo get_the_author_meta('first_name').' '.get_the_author_meta('last_name');?></h4>
                <ul class="social_ic">
                    <?php
                    $author_id = get_the_author_meta('ID');
                    $author_twitter = get_field('author_twitter','user_'.$get_author_id);
                    $author_linkedin = get_field('author_linkedin','user_'.$get_author_id);
                    $author_email = get_field('author_email','user_'.$get_author_id);
                    $author_telegram = get_field('author_telegram','user_'.$get_author_id);
                    ?>
                    <?php
                    if ( ! empty($author_twitter) ) : ?>
                        <li>
                            <a href="<?= $author_twitter; ?>">
                                <img src="<?= get_template_directory_uri(); ?>/img/sc-twitter.png" alt=""/>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php
                    if ( ! empty($author_linkedin) ) : ?>
                        <li>
                            <a href="<?= $author_linkedin; ?>">
                                <img src="<?= get_template_directory_uri(); ?>/img/sc-linkedin-letters.png" alt=""/>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php
                    if ( ! empty($author_email) ) : ?>
                        <li>
                            <a href="<?= $author_email; ?>">
                                <img src="<?= get_template_directory_uri(); ?>/img/sc-email.png" alt=""/>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php
                    if ( ! empty($author_telegram) ) : ?>
                        <li>
                            <a href="<?= $author_telegram; ?>">
                                <img src="<?= get_template_directory_uri(); ?>/img/sc-twitter.png" alt=""/>
                            </a>
                        </li>
                    <?php endif; ?>

                </ul>
            </div>
        </div>
        <?php
        if( have_rows('post_content') ):
            while ( have_rows('post_content') ) : the_row();
                if( get_row_layout() == 'subtitle' ): ?>
                    <h3><?php the_sub_field('subtitle_text'); ?></h3>
                <?php elseif( get_row_layout() == 'title_text_image' ): ?>
                    <div class="blog_smlist">
                        <h4><?php the_sub_field('tti_title'); ?></h4>
                        <?php the_sub_field('tti_content'); ?>
                        <div class="blog_thumb">
                            <?php $tti_image = get_sub_field('tti_image');
                            if( !empty($tti_image) ): ?>
                                <img src="<?php echo $tti_image['url']; ?>" alt="<?php echo $tti_image['alt']; ?>" />
                            <?php endif; ?>
                            <span><?php the_sub_field('tti_image_text'); ?></span>
                        </div>
                    </div>
                <?php elseif( get_row_layout() == 'title_and_text' ): ?>
                    <div class="blog_smlist">
                        <h4><?php the_sub_field('tat_title'); ?></h4>
                        <?php the_sub_field('tat_text'); ?>
                    </div>
                <?php endif;
            endwhile;
        endif;
        ?>
    </div>