<?php while(have_posts()) : the_post(); ?>
  <div class="preview">
    <div class="preview-thumbnail">
      <a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail( ); ?>
      </a>
    </div>
    <div class="preview-text">
      <h2><a href="<?php the_permalink(); ?>" class="preview-title-link m-0 p-0"><?php the_title(); ?></a></h2>
    
      <div class="flex-that">
        <div>
          <?php
            if (!has_category('chapters')) {
              $category = get_the_category();
              echo"<span class='badge bg-primary small-text m-0'>" . $category[0]->cat_name . "</span>";
            }
          ?>
        </div>
        <div>
          <time><span class="badge bg-primary small-text m-0"><?php the_time('d/m/Y') ?></span></time>
        </div>
      </div>
      <div class="preview-excerpt" aria-excerpt="true"><?php the_excerpt(); ?></div>
    </div>
  </div>
<?php endwhile; ?>