WordPress themes 2021, Part 5 – Archive Pages



The archive page

The archive page is used by WordPress to display category type pages that have a list of blog posts. We will be building a layout similar to the page below.

Copy and paste the code below into archive.php.

<?php get_header();?>
<section class="page-wrap">
<div class="container">
    <?php get_template_part('includes/section', 'archive')?>
    <?php previous_posts_link()?>
    <?php next_posts_link()?>
</div>
</section>
<?php get_footer();?>

Template parts

The above page uses a template part named section-archive.php. this section contains the WordPress loop.

<?php if (have_posts()): while(have_posts()): the_post();?>
<div class="card mb-3 p-1">
    <div class="card_body">
        <h3 class="blog-head"><?php the_title()?></h3>
        <?php the_excerpt();?>
        <a href="<?php the_permalink()?>" class="btn btn-success">Read More...</a>
    </div>
</div>
<?php endwhile; else: endif; ?>