Create WordPress Archive page

Archive page is responsible for land various post list, such as categories post, tags post etc.

  • Create file called content-archive.php under the directory called template-parts, add the below codes

<div class="container">
    <article class="blog-post">
        <a href="<?php the_permalink() ?>">
            <?php the_title( '<h2>', '</h2>' ); ?>
        </a>
        <p class="blog-post-meta"><?php the_time('F j, Y'); ?> by <span><?php the_author() ?></span></p>
        <div class="content">
            <?php the_content(); ?>
        </div>
    </article>
</div>
  • Now create a file called archive.php and add below codes

<?php get_header() ?>

<div class="container">
    <div class="row">
        <div class="col-md-10">
            <?php
            if ( have_posts() ) :
                while ( have_posts() ) : the_post();
                    get_template_part("template-parts/content", "archive");
                endwhile;
            endif;
            ?>
        </div>
        <div class="col-md-2">
            <div id="right-sidebar" class="sidebar">
                <?php dynamic_sidebar( 'h2wp-right-sidebar' ); ?>
            </div>
        </div>
    </div>
</div>


<?php get_footer() ?>