Top Ad unit 728 × 90

How to Create a WordPress Archives Page


The chronological nature of blogging means that great articles can get lost in your archives. Placing a search bar and an archives widget in your sidebar can make it easier for visitors to search through older content.
You can extend this further by creating a dedicated archives page. Unfortunately, not every WordPress theme comes with an archives page template and those that do are not always structured the way you want.
Thankfully, it is very easy to create your own archives page. All you have to do is create an archives page template and then assign it to a page.
In this tutorial, I would like to show you how you can build an archives page for your WordPress website.
Before we get started, I recommend checking whether your current WordPress theme already has an archives template. This will help you determine whether you need to create an archives template from scratch or simply modify an existing archives template.
The quickest way to see if your activated WordPress theme has an archives template is to create or edit a page (not a blog post!). At the right hand side of the post editor you will see the Page Attributesmenu. This allows you to assign a custom page template to any WordPress page.
If your activated WordPress theme already has an archives page template, you will see an option for an archives template. The name of the archives template depends on what it has been named in template itself. Usually, it is named Archive or Archives.
Many themes do not include an archives template, though WordPress users may be led to believe they do because they include a template named archive.php. Take the default WordPress themeTwenty Fourteen, for example.
If you modify a page, you will see that the theme does not include an archives page template. However, a quick look at the templates of of Twenty Fourteen highlights that it has a template called archive.php.
In WordPress, the archive.php template is an important template that is placed highly in theWordPress template hierarchy. The only template with more importance is index.php.
WordPress allows you to display older blog posts in a number of ways. Category archives can be displayed using the category.php template and tag archives can be displayed using the tag.php template. Whereas date archives use date.php and author archives use author.php. None of these archive templates are essential.
If WordPress does not find any of these archive templates in a WordPress template, it will use the archive.php template to display archives instead. And if for any reason an archive.php template is not available, WordPress will use the index.php template to display archives.
In contrast, the archives.php template is a page template that can be assigned to any page. It is used to create a dedicated archives page.
  • Archive.php – Used to display category, date, author, tag, taxonomy, and custom post type archives
  • Archives.php – A page template that is used to create a dedicated archives page
Despite these templates being used for completely different purposes, they are regularly confused by WordPress users due to their names. To avoid this confusion, many WordPress developers name the archives template something different, such as page-archives.php or archives-template.php. This is not necessary as after you define the file as a page template, WordPress will append the word template to the file in your theme file editor.
If no archives template exists, you should create a blank file and name it something like archives.php or page-archives.php. If you had to upload that blank template to your WordPress theme directory, you will see the file listed in your template list.
Like all WordPress page templates, the name of the template that appears in the Page Attributes section of the WordPress page editor is defined using the Template Name string.
In the example below, I have named my archives template Archives; however I could have named it anything. This code would be placed at the top of our PHP page template.
The most practical way of creating an archives page template is to modify the code of your WordPress theme’s page.php template. The Creating an Archive Index tutorial in the WordPress Codex gives an example of this.
As you can see from the code below, this archives page template would display a search form, archives by month and archives by category.
The above code is a good example of an archives page template, however the exact code of your archives page template will depend on the theme you are using. If you used the above code for an archives page template with your current theme, it is unlikely to be styled correctly as it is not based on your theme’s page.php template.
In practice, creating a custom archives page template is slightly more complicated. This is particularly true for themes that call the content of page templates from different files. For example, in Twenty Fourteen, the content part of a page is stored in a file entitled content-page.php.
If I wanted to create an archives page template for Twenty Fourteen, I could place all code in the archives template or call the content for archives from a new file I create entitled content-pagearchive.php. Neither option is better than the other. Simple use the method that you feel is best.
While placing code in specific content templates is tidier, I prefer to place all the code for the archives page template in one file. Here is an example of a simple archives page template I created for the Twenty Fourteen theme.
At first glance, the above code may seem complex; however it is actually straight forward. All I did was copy the code from page.php, replace the call to the page content template tag with the code from content-page.php, and then insert the code to display archives.
You can repeat these steps with any WordPress theme in order to create a unique archives page template for your website.
There are a number of WordPress template tags that can be used in your archives page template. This includes:
How to Create a WordPress Archives Page Reviewed by Unknown on 10:31 PM Rating: 5

No comments:

All Rights Reserved by Boca Raton Real Estate © 2014 - 2015
Powered By Blogger, Designed by Sweetheme

Contact Form

Name

Email *

Message *

Powered by Blogger.