<?php
/**
 * The main template file.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package ca-simplex-blog
 */

get_header();
?>
  <main id="content">
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-8 col-12">
          <div class="singlepost-category">
            <?php
              $categories = get_the_category();
              if ( ! empty( $categories ) ) {
                  foreach( $categories as $category ) {
                      echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
                  }
              }
            ?>
          </div>
          <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php get_template_part( 'template-parts/content', get_post_format() ); ?>
          <?php endwhile; ?>
            <?php the_posts_pagination( array(
              'prev_text' => __( 'Previous page', 'ca-simplex-blog' ),
              'next_text' => __( 'Next page', 'ca-simplex-blog' ),
              'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'ca-simplex-blog' ) . ' </span>',
            ) ); ?>
          <?php else : ?>
            <?php get_template_part( 'template-parts/content', 'none' ); ?>
          <?php endif; ?>
          <div class="post-navigation">
            <div class="nav-previous"><?php previous_post_link( '%link', '%title' ); ?></div>
            <div class="nav-next"><?php next_post_link( '%link', '%title' ); ?></div>
          </div>
    </div>
    <div class="col-lg-4 col-md-4 col-12">
      <?php get_sidebar(); ?>
    </div>
  </div>
  <?php
      // If comments are open or there is at least one comment, show the comment template.
      if ( comments_open() || get_comments_number() ) {
        comments_template();
      }

    ?>

</div>
</main>

<?php
get_footer(); ?>
