<?php $terms = get_the_terms(get_the_ID(), 'category'); ?>

<article <?php post_class("rt-post is-style-grid border rounded-md overflow-hidden") ?>>
    <?php if (has_post_thumbnail() && rt_get_option('post_element_thumbnail', true)) : ?>
        <figure class="rt-post__thumbnail rt-img is-img-full my-0" style="aspect-ratio:<?php echo esc_attr(rt_get_option('post_image_ratio', '3/2')) ?>">
            <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
                <?php the_post_thumbnail(rt_get_option('post_image_size', 'medium_large'));  ?>
            </a>

            <?php if ($terms && !is_wp_error($terms) && rt_get_option('post_element_category', true)) : ?>
                <div class="rt-post-terms wp-block-post-terms is-style-overlay has-xx-small-font-size is-style-colored">
                    <?php foreach ($terms as $term) : ?>
                        <a class="<?php echo 'category-' . esc_attr($term->slug) ?>" href="<?php echo esc_url(get_tag_link($term->term_id)) ?>">
                            <?php echo $term->name ?>
                        </a>
                    <?php endforeach; ?>
                </div>
            <?php endif ?>

        </figure>
    <?php endif ?>
    <div class="rt-post__body is-layout-flow py-40 px-40">

        <h3 class="rt-post__title has-medium-font-size has-link-overlay line-clamp-3">
            <a href="<?php the_permalink() ?>"><?php echo get_the_title() ?></a>
        </h3>

        <?php rt_get_template_part('post/post-meta') ?>

        <?php if (rt_get_option('post_element_content', true)) : ?>
            <div class="rt-post__excerpt has-small-font-size line-clamp-3 mt-20">
                <?php echo wp_trim_words(get_the_excerpt(), rt_get_option('post_excerpt_length', 15)) ?>
            </div>
        <?php endif ?>

        <?php if ($terms && !is_wp_error($terms)) : ?>
            <div class="wp-block-post-terms is-style-colored has-xx-small-font-size">
                <?php foreach ($terms as $term) : ?>
                    <a class="<?php echo 'category-' . esc_attr($term->slug) ?>" href="<?php echo esc_url(get_tag_link($term->term_id)) ?>">
                        <?php echo $term->name ?>
                    </a>
                <?php endforeach; ?>
            </div>
        <?php endif ?>

    </div>
</article>