Why Should You Change the Way WordPress Archives Are Displayed in Your Sidebar?
Compact Archive Creation
By being a little wider, the compact archives list saves vertical space. As a result, it might be better suited to a footer or archives page than than a sidebar.
The plugin is, however, highly adjustable, and you can make it narrower by showing only the first initial or a number for each month. More information on how to make compact archives in WordPress may be found in our guide.
Using a Collapsible Outline to Display Archives
Displaying a collapsible outline of the years and months that you wrote blog content is another method to deal with big archives listings.
The Collapsing Archives plugin must be installed and activated in order to accomplish this. You must go to Appearance » Widgets and add the ‘Compact Archives‘ widget to your sidebar after activation.
On our sample website, this is how it looks.
Setting a Limit on the Number of Archive Months Shown
Limiting the number of months displayed to, say, the latest six months is a third technique to keep your archives list from being too big.
You’ll need to add code to your WordPress theme’s files to accomplish this. See our article on how to copy and paste code in WordPress if you haven’t done it before.
Add the following code snippet to your functions.php file, a site-specific plugin, or a code snippets plugin as the initial step.
Edit the number on line 6 to adjust the number of months displayed. If you modify the number to ’12,’ for example, it will show 12 months of archives.
You may now add a ‘Custom HTML’ widget to your sidebar by going to Appearance » Widgets. Then, in the widget box, copy and paste the following code:
Archives are listed on a daily, weekly, monthly, or annual basis.
The Annual Archive plugin will provide you greater control over how your archives are displayed. It allows you to organize your archives by decade and list them daily, weekly, monthly, annually, or alphabetically.
Install and activate the Annual Archive plugin to get started. The Annual Archive widget can then be dragged to your sidebar from the Appearance » Widgets page.
You can choose whether to display a list of days, weeks, months, years, decades, or posts after giving the widget a title. You can limit the amount of archives displayed, choose a sort option, and add additional text by scrolling down to other options.
If you go to Settings » Annual Archive, you may use custom CSS to further modify the archive list.
Monthly Archives are organized by year.
We were once working on a site design for a client who needed monthly archives organized by year in the sidebar. Because this client only wanted to show the year once on the left, it was challenging to code.
Andrew Appleton was able to tweak some code for us. Because Andrew’s code lacked a limit option for the archives, the list displayed all archive months. We included a limit parameter that limited the number of months displayed to only 18 at any given moment.
To show custom WordPress archives, insert the following code into your theme’s sidebar.php file or any other file where you wish to display them:
You must adjust line 19 where the current $limit value is set to 18 if you want to change the number of months displayed.
You can also display the number of posts in each month by inserting the following code between lines 12–16 of the above code:
<?php echo $month->post_count; ?>
To show the archive list correctly on your website, you’ll need to apply custom CSS. On our client’s website, we used CSS that looked like this:
We hope this lesson showed you how to alter the way WordPress archives are displayed in your sidebar.