<?php
/**
 * Template part for displaying posts.
 */
// Metabox
$confin_id    = ( isset( $post ) ) ? $post->ID : 0;
$confin_id    = ( is_home() ) ? get_option( 'page_for_posts' ) : $confin_id;
$confin_meta  = get_post_meta( $confin_id, 'page_type_metabox', true );
$confin_large_image =  wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'fullsize', false, '' );
$confin_large_image = $confin_large_image ? $confin_large_image[0] : '';
$confin_alt = get_post_meta($confin_large_image, '_wp_attachment_image_alt', true);
$confin_read_more_text = cs_get_option('read_more_text');
$confin_read_text = $confin_read_more_text ? $confin_read_more_text : esc_html__( 'Read More', 'confin' );
$confin_post_type = get_post_meta( get_the_ID(), 'post_type_metabox', true );
$confin_metas_hide = (array) cs_get_option( 'theme_metas_hide' );
  // Sticky
$post_class = get_post_class();
$find_sticky = array_search( 'sticky', $post_class );
if ( ! empty( $confin_post_type['gallery_post_format'] ) ) {
  $post_format_class = ' slider-post';
} else {
  $post_format_class = ' ';
}
?>
 <div <?php post_class('post'.$post_format_class); ?>>
  <?php
    if ( $find_sticky ) {
        echo '<div class="sticky-badge"><h2>'.esc_html__( 'Featured', 'confin' ).'</h2></div>';
    }
    if ( ! empty( $confin_post_type['gallery_post_format'] ) ) { ?>
    <div class="entry-media post-slider"
        data-nav="true"
        data-autoplay="true"
        data-auto-height="true"
        data-dots="true">
    <?php
      $confin_ids = explode( ',', $confin_post_type['gallery_post_format'] );
      foreach ( $confin_ids as $id ) {
        $confin_attachment = wp_get_attachment_image_src( $id, 'full' );
        $confin_alt = get_post_meta($id, '_wp_attachment_image_alt', true);
        echo '<img src="'. $confin_attachment[0] .'" alt="'. esc_attr( $confin_alt ) .'" />';
      }
    ?>
   </div>
  <?php } elseif ( $confin_large_image ) { ?>
    <div class="entry-media">
        <img src="<?php echo esc_url( $confin_large_image ); ?>" alt="<?php echo esc_attr( $confin_alt ); ?>">
    </div>
    <?php } ?>
     <div class="entry-body">
      <ul class="meta">
          <li><i class="ti-user"></i>
             <?php if ( !in_array( 'author', $confin_metas_hide ) ) { // Author Hide
               printf( esc_html__(' By:','confin') .' <a href="%1$s" rel="author">%2$s</a>',
                  esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                  get_the_author()
                );
            } ?>
          </li>
          <li><i class="ti-calendar"></i><a href="<?php echo esc_url( get_permalink() ); ?>"><?php echo esc_html( get_the_date() );  ?></a></li>
          <li>
             <i class="ti-comment"></i><a class="confin-comment" href="<?php echo esc_url( get_comments_link() ); ?>">
              <?php printf( esc_html( _nx( 'Comments (%1$s)', 'Comments (%1$s)', get_comments_number(), 'comments title', 'confin' ) ), number_format_i18n( get_comments_number() ),'<span>' . get_the_title() . '</span>' ); ?>
            </a>
          </li>
      </ul>
       <h3><a href="<?php echo esc_url( get_permalink() ); ?>"><?php echo get_the_title(); ?></a></h3>
      <div class="entry-details">
        <p><?php
              $blog_excerpt = cs_get_option('theme_blog_excerpt');
              if ($blog_excerpt) {
                $blog_excerpt = $blog_excerpt;
              } else {
                $blog_excerpt = '25';
              }
              confin_excerpt($blog_excerpt);
              echo confin_wp_link_pages();
          ?></p>
        <a href="<?php echo esc_url( get_permalink() ); ?>" class="theme-btn-s2"><?php echo esc_attr($confin_read_text); ?> <i class="ti-arrow-right"></i></a>
      </div>
    </div>
</div>
