<?php if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

$counter = 0; // initilize counter for blog culum no
// get blog pattern value from theme setting for enable or not
$user_id = '1';
$codemaster_themeopt_blogpattern =  get_user_meta( $user_id, 'codemaster_themeopt_blogpattern', true );
if(!empty($codemaster_themeopt_blogpattern) && $codemaster_themeopt_blogpattern == "No") { 
    $counter = 1;
}
get_header();
?>
<div class="ranking_page_banner">
	 <div class="container">
	   <h1 class="text-white display-3"><?php sanitize_title(the_title()) ?></h1>
	   <div class="doemaster-breadcrum">
	   <?php if (function_exists('codemaster_breadcrumbs'))  codemaster_breadcrumbs();  ?>
	   </div>
	 </div>
</div>
<section class="blogpage site-content py-3">
<div class="container">
<div class="row row-cols-1 row-cols-lg-3 row-cols-lg-4 g-4 g-lg-4">
  <!-- Start the Loop. -->
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post();   $counter++;
    if ( 1 === $counter ) { ?>
       <div class="post col-md-12 col-lg-12 image-block full-width">
    <div class="rank-post-content card h-100 shadow-sm">
		<div <?php post_class(); ?>>
 	<!-- Display the Title as a link to the Post's permalink. -->
 	<div class="image-block-inner">
    <?php if ( has_post_thumbnail() ) {
        the_post_thumbnail( 'codemaster-post-image-size' );
    } else {
    echo '<img width="1200" height="400" alt="Image not found" src="' . esc_url(get_stylesheet_directory_uri()). '/assets/images/not-found.webp" />';
    }
    ?>
    </div>
    <div class="card-body">
 	<h2 class="rk-post-heading h3 mt-1"  id="post-<?php the_ID(); ?>">
 	    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title( sprintf(
			__( 'Continue reading %s', 'codemaster' ),
			the_title( '<span class="screen-reader-text">', '</span>', false )
		) ); ?>
		</a>
	</h2>
 	<!-- Display the date (November 16th, 2022 format) and a link to other posts by this posts author. -->
      	<div class="post-info-text">
      	    <span><i class="icofont-clock-time"></i> <?php the_time('F jS, Y'); ?> </span> 
     	    <span><i class="icofont-user-alt-7"></i> by <?php the_author_posts_link(); ?> </span>
	    </div>
     	<div class="entry mt-1">
     		<?php echo wp_trim_words( get_the_content(), 20, '...' ); // the_content(); ?>
     	</div>
     	<!-- Display a comma separated list of the Post's Categories. -->
     	<p class="postmetadata"><?php esc_html_e( 'Posted in', 'codemaster' ); ?> <?php the_category( ', ' ); ?></p>
     	</div>
 	</div>
  </div>
</div>
<?php  } else { ?>
 <div class="post col-md-4 col-lg-4 image-block full-width">
    <div class="rank-post-content card h-100 shadow-sm">
		<div <?php post_class(); ?>>
 	<!-- Display the Title as a link to the Post's permalink. -->
 	<div class="image-block-inner">
     <?php if ( has_post_thumbnail() ) {
        the_post_thumbnail( 'codemaster-post-image-size' );
    } else {
    echo '<img width="354" height="285" alt="Image not found" src="' . esc_url(get_stylesheet_directory_uri()). '/assets/images/not-found.webp" />';
    }
    ?>
    </div>
    <div class="card-body">
 	<h2 class="rk-post-heading h3 mt-1"  id="post-<?php the_ID(); ?>">
 	    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title( sprintf(
			__( '%s', 'codemaster' ),
			the_title( '<span class="screen-reader-text">', '</span>', false )
		) ); ?>
		</a>
	</h2>
 	<!-- Display the date (November 16th, 2022 format) and a link to other posts by this posts author. -->
      	<div class="post-info-text">
      	    <span><i class="icofont-clock-time"></i> <?php the_time('F jS, Y'); ?> </span> 
     	    <span><i class="icofont-user-alt-7"></i> by <?php the_author_posts_link(); ?> </span>
	    </div>
     	<div class="entry mt-1">
     		<?php echo wp_trim_words( get_the_content(), 20, '...' ); // the_content(); ?>
     	</div>
     	<!-- Display a comma separated list of the Post's Categories. -->
     	<p class="postmetadata"><?php esc_html_e( 'Posted in', 'codemaster' ); ?> <?php the_category( ', ' ); ?></p>
     	</div>
 	</div>
  </div>
 </div>
  <!-- close The if else condition -->
 <?php }  ?>
 <!-- Stop The Loop -->
 <?php endwhile; ?>
</div>
<div class="text-center pt-4 pb-2 ranking-pg">
    <div class="pagination">
	<?php
	 the_posts_pagination( array(
	    'prev_text' => __( 'Prev', 'codemaster' ),
	    'next_text' => __( 'Next', 'codemaster' ),
	) ); ?>
  </div>
</div>
<!--  <div class="nav-previous alignleft"><?php // previous_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php // next_posts_link( 'Newer posts' ); ?></div> -->
<?php else : ?>
 	<!-- The very first "if" tested to see if there were any Posts to -->
 	<!-- display.  This "else" part tells what do if there weren't any. -->
 	<p><?php esc_html_e( 'Sorry, no posts matched your criteria.', 'codemaster' ); ?></p>
 	<!-- REALLY stop The Loop. -->
 <?php endif; ?>
</div>
</section>
<?php get_footer(); ?>