Now that we have the infrastructure for the home page and the hierarchy of sub-pages, we need to explore content that is organized by time, i.e., posts, for ideas like press release archives.
First, we need to update the default category for posts and change its name from
Uncategorized to something more useful, e.g.,
Press Releases, by using
admin > Posts > Categories.
Then we create a couple of posts by using
admin > Posts > All Posts.
Finally, we can go into
admin > Appearance .> Menus to add the archive screen for the
Press Releases category to the menu.
At this point, however, navigating to the category archive does not result in the desired result as it is picking up the
index.php file for the template. Looking at the template hierarchy again we see that we need to create
archive.php by simply copying over
page.php: https://developer.wordpress.org/themes/basics/template-hierarchy/.
The problem now, however, is that the screen is not geared towards a list of posts. A better layout would a list of as follows:
Post Title (linked to full post)
Post Date
Beginning part of the post.
To implement this, we update
archive.php as follows:
archive.php
<html>
<head>
<title>Barebones</title>
<?php wp_head() ?>
</head>
<body>
<?php wp_nav_menu(array('theme_location' => 'header-menu')); ?>
<?php if (function_exists('yoast_breadcrumb')) {
yoast_breadcrumb();
}?>
<?php while (have_posts()) : the_post(); ?>
<p><b><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></b><br />
<i><?php the_time('F j, Y'); ?></i><br />
<?php the_content('', false); ?></p>
<?php endwhile; ?>
<?php wp_footer() ?>
</body>
</html>
Now that we have the archive, the link to the full post brings up our
index.php for the template. To fix this, we copy
page.php to
single.php and update as follows:
single.php
<html>
<head>
<title>Barebones</title>
<?php wp_head() ?>
</head>
<body>
<?php wp_nav_menu(array('theme_location' => 'header-menu')); ?>
<?php if (function_exists('yoast_breadcrumb')) {
yoast_breadcrumb();
}?>
<?php while (have_posts()) : the_post(); ?>
<p><b><?php the_title(); ?></b><br />
<i><?php the_time('F j, Y'); ?></i><br /></p>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_footer() ?>
</body>
</html>
Finally, in order to get the breadcrumbs to work for post pages change
admin > SEO > Advanced > Taxonomy to... > Posts to
Category.