How to Create Compact Archives in WordPress


After a few years of blogging you will see how a WordPress archive can quickly get out of hand. What you need is a way to compress everything so that your posts are easier to find. Although we have already shown you how you can customize the display of WordPress archives in your sidebar, today we are going to use a plugin called Compact Archives for WordPress.

Compact Archives as displayed on WPBeginner

There are three ways you can use this plugin. The first involves a widget that you can place in your sidebar, secondly you can use shortcode in your posts and pages, lastly you can use template tags inside your theme files.

Before we do anything else though, install and activate the Compact Archives Plugin. The first method we are going to go over is the widget method.

Using The Compact Archives Widget

To use the widget method, you need to go to Appearance » Widgets. There you will see Compact Archives widget in the available widgets. You need to drag and drop Compact Archives Widget to your sidebar.

Compact archives widget

The widget will allow you to choose a style for your compact archives and enter a widget title. You can also choose to transform the initials to uppercase. Save your widget settings and preview your site.

Using Shortcodes to Display Compact Archives

To display compact archives inside a post, or a page, you can use these shortcodes:


This shortcode will simply show your compact archives. The shortcode accepts the style, before, and after parameters. To display your compact archives in block, you will use this shortcode:

[compact_archive style="block"]

Using before and after parameters, you can add HTML that you would want to appear before and after the compact archives. In the following shortcode, we have displayed the compact archive in numeric format and wrapped it around paragraph tags.

[compact_archive style="numeric" before="<p>" after="</p>"]

Displaying Compact Archives in Custom Templates

If you want more control over where the archives should go, then you can manually insert the code into your template files. We have seen these used on custom archive pages which can be created using custom WordPress page templates. Wherever you want it to appear insert the following code:

  <ul> <?php compact_archive(); ?> </ul>  

There are also some parameters that you can adjust

  compact_archive($style='initial', $before='<li>', $after='</li>');  

These are the same parameters that you can change using the widget. For example, $style == 'initial' will would display only month name initials and should fit right inside a sidebar. Using $style == 'block', the display will fit the main column of a page. Using $style == ‘numeric’, the months will be displayed numerically.

If you are manually adjusting the code you can also change the $before and $after parameters which determine what code will wrap each line of output (default is list item).

Styling your Archive

Months with no posts in them are wrapped in

<span class="emptymonth"></span>

so you can target them in your CSS file and make it seem as if they are faded into the background our otherwise less visually significant than the months that do have posts.

We hope you this article helped you create compact archives in WordPress. Please leave your comments or join us on Twitter.

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.