<?php
/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 */

?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <div class="post-wrap">

        <?php
            // Retrieve featured image values from the database.
            $prime_business_image_id       = get_post_thumbnail_id();
            $prime_business_image_path     = wp_get_attachment_image_src( $prime_business_image_id, 'full', true );
            $prime_business_image_alt      = get_post_meta( $prime_business_image_id, '_wp_attachment_image_alt', true );
            $prime_business_alt            = !empty( $prime_business_image_alt ) ? $prime_business_image_alt : the_title_attribute( 'echo=0' );
        ?>

        <?php if ( has_post_thumbnail() ) : ?>
            <div class="thumbnail-area">
                 <a href="<?php the_permalink(); ?>">
                    <img src="<?php echo esc_url( $prime_business_image_path[0] ); ?>" alt="<?php echo esc_attr( $prime_business_alt ); ?>" />
                </a>
                <div class="post-date">
                    <span><?php echo esc_html( get_the_date() ); ?></span>
                </div><!-- /.post-date -->
            </div><!-- /.thumbnail-area -->
        <?php endif; ?>

        <div class="post-excerpt post-loop">
                <a href="<?php the_permalink(); ?>"><?php the_title( '<h3>', '</h3>' ); ?></a>

                <?php if( get_post_type() == 'post' ) : ?>
                <div class="post-details">
                    <?php if ( ! has_post_thumbnail() ) : ?>
                        <div class="post-date">
                            <span><?php echo esc_html( get_the_date() ); ?></span>
                        </div><!-- /.post-date -->
                    <?php endif; ?>

                    <div class="excerpt-author">
                        <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo get_avatar( get_the_author_meta( 'ID' ) ); ?></a>
                        <div class="author-name">
                            <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php the_author(); ?></a>
                        </div><!-- /.author-name -->
                    </div><!-- /.excerpt-author -->

                    <?php
                        $prime_business_categories_list = get_the_category_list( esc_html__( ' / ', 'prime-business' ) );
                        if ( $prime_business_categories_list ) {
                            printf(
                                /* translators: 1: SVG icon. 2: posted in label, only visible to screen readers. 3: list of categories. */
                                '<div class="excerpt-category">%1$s</div><!-- /.excerpt-category -->',
                                $prime_business_categories_list
                            ); // WPCS: XSS OK.
                        }
                    ?>

                    <div class="excerpt-comments">
                        <div class="comments-count">
                            <?php comments_number( esc_html__( '0 Comment', 'prime-business' ), esc_html__( '1 Comment', 'prime-business' ), esc_html__( '% Comments', 'prime-business' ) ); ?>
                        </div><!-- /.comments-count -->
                    </div><!-- /.excerpt-comments -->
                </div><!-- /.post-details -->
                <?php endif; ?>
            <p class="post-excerpt"><?php the_excerpt(); ?></p>

            <?php if( empty( $post->post_title ) ) : ?>
                <a href="<?php the_permalink(); ?>"><?php esc_html_e( 'Read More', 'prime-business' ); ?></a>
            <?php endif; ?>
        </div><!-- /.post-excerpt -->
    </div><!-- /.post-wrap -->
</div>
