<?php
/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package express-movers
 */

?>
<article class="maincontent post-item">
    <?php
    $post_id = get_the_ID();
    $permalink = get_permalink( $post_id );
    $date_string = get_the_date( 'F j, Y', $post_id );

    // Prefer excerpt; fallback to trimmed content.
    $excerpt_raw = has_excerpt( $post_id ) ? get_the_excerpt( $post_id ) : get_the_content( null, false, $post_id );
    $excerpt = wp_trim_words( wp_strip_all_tags( $excerpt_raw ), 22, '' );
    $title = get_the_title( $post_id );
    ?>

  <div class="image-container">
            <!-- Featured Image -->
           

            <!-- Text Overlaid on the Image -->
            <div class="overlay-text">
                <div>
                    <h4 class="post-date">
                        <a href="<?php the_permalink();?>"><?php echo esc_html(get_the_date('F j, Y')); ?></a>
                    </h4>
                </div>
                <div class="meta-para mt-4">

                    <div class="entry-container">
                        <header>
                            <div class="entry-meta d-flex">
                            </div><!-- .entry-meta -->
                            <h2 class="page-title mb-3">
                                <?php
                                $express_movers_content_limit = 2; 
                                    // Wrap the post title in an anchor tag linking to the post
                                    echo '<a href="' . esc_url(get_permalink()) . '">' . esc_html(wp_trim_words(get_the_title(), $express_movers_content_limit, '')) . '</a>';
                                ?>
                            </h2>

                        </header>
                        <!-- </?php the_content(); ?> -->
                        <p><?php
                        // Set a word limit, e.g., 40 words
                        $express_movers_content_limit = 18; 

                        // Get the content and trim it
                        echo wp_kses_post(wp_trim_words(get_the_content(), $express_movers_content_limit, ''));
            
                         ?></p>

                    </div>
                </div>
            </div>
        </div>
</article>