Given code for wordpress create archive page for wordpress theme. search engine sites will look for two main file. First sitemap.xml file and archive page. First I would say somthing about archive page in any website. Archive page is very important for SEO purpose.
Create an Archive Page in your WordPress theme
If you do not having archive page in your website so you are lacking somewhere in SEO for your website. What I am going to show in this article, How to create the archive page for worpdress theme or website. In wordpress creating the archive is very easy.
Follow my steps to create the archive page in wordpress site.
- Open your wordpress theme folder and copy the single.php as named archive.php
Note: dont copy index.php file as archive.php. It may have different UI and programming attribute in index.php. - Then copy archive.php as archive_template.php new file.
- Open the archive_template.php file and copy paste the following code in top of file.
<?php /* Template Name: Archives Page */ ?>
- Again open the archive_template.php file and find the post loop. Between the loop copy past the following code.
<h1> All Archives in dropdown</h1> <select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select> <br><br> <h1> All category</h1> <ul><?php wp_list_cats('sort_column=name&optioncount=1') ?></ul> <br><br> <h1> All Archives</h1> <ul><?php wp_get_archives('type=monthly&show_post_count=1') ?></ul>
Above code will give you the archive with dropdown and archive with category name with post count and archive with month and post count.
- After doing this upload two new files to server in wordpress theme folder (archive.php and archive_template.php).
- Go to your wordpress Admin panel using browser
- Create the new page with title “Archive” and put some information about your website in that page.(Dont publish the page wait and follow next steps.)
- Check the template section (right side under attribute section). Choose archive page as template and publish and save the page.
That sit. You are able to see the archive page for your website.