<?php
if( !defined('ABSPATH') ){ exit(); }
get_header();
?>
<div style="display: none;">
    <?php
    if( is_search() ){
        echo '<h1>Search: ' . get_search_query() . '</h1>';
    }elseif( is_category() ){
        echo '<h1>Category: ' . single_cat_title('', false) . '</h1>';
    }elseif( is_tag() ){
        echo '<h1>Tag: ' . single_tag_title('', false) . '</h1>';
    }elseif( is_author() ){
        echo '<h1>Author: ' . get_the_author() . '</h1>';
    }elseif( is_date() ){
        echo '<h1>Archives: ' . get_the_date('F Y') . '</h1>';
    }else{
        echo '<h1>Archives</h1>';
    }
    if( !is_search() ){
        $desc = term_description();
        if( $desc ){ echo '<div>' . $desc . '</div>'; }
    }
    ?>
</div>

<?php if( have_posts() ): ?>
    <?php while (have_posts()) : the_post(); ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <div>
                <span><?= get_the_date(); ?> | <?php the_author(); ?></span>
            </div>
            <div> <?php the_excerpt(); ?></div>
        </article>
    <?php endwhile; ?>

    <div>
        <?php
            the_posts_pagination([ 'mid_size'=>2, 'prev_text'=>'←', 'next_text'=>'→' ]);
        ?>
    </div>
<?php else : ?>
    <?php if (is_search()) : ?>
        <h2>No results found</h2>
        <p>Try another keyword.</p>
        <?php get_search_form(); ?>
    <?php else : ?>
        <h2>No posts found</h2>
    <?php endif; ?>
<?php endif; ?>

<?php get_footer(); ?>