How to Customize the Display of WordPress Archives in Your Sidebar

[agentsw ua=’pc’]

Do you need to customize how your WordPress archives are displayed in the sidebar?

The default WordPress archives widget offers limited customization. You may like your post archives to use less space, display more information, or have a more attractive appearance.

In this article, we’ll show you how to customize the display of WordPress archives in your sidebar.

customize the display of wordpress archives in sidebar og

Contents

Why Customize the Display of WordPress Archives in Your Sidebar?

Your WordPress website comes with an archives widget that lets you display monthly blog post archive links in a sidebar.

The widget has two customization options: you can display the archive list as a dropdown menu, and you can display the post counts for each month.

The Default WordPress Archives Widget

However, you may wish to display your sidebar archive list differently. For example, as your site grows, the default list may become too long, or you may want to make it easier for your visitors to navigate.

Let’s look at some ways to customize the display of WordPress archives in your sidebar:

Creating Compact Archives

If your archives list has become too long, then you can create a compact archive that displays your posts using much less space.

You’ll need to install and activate the Compact Archives plugin which is developed and maintained by the WPBeginner team. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you can add the compact archives to a post, page, or widget using the ‘WPBeginner’s Compact Archives’ block.

The Compact Archives Plugin

The compact archives list saves vertical space by being a little wider. That means it may fit better in a footer or archives page than in a sidebar.

However, the plugin is quite configurable and you can make it narrower by displaying just the first initial or a number for each month. You can learn more in our guide on how to create compact archives in WordPress.

Displaying Archives in a Collapsable Outline

Another way to deal with long archives lists is to display a collapsable outline of years and months when you published blog posts.

To do this, you need to install and activate the Collapsing Archives plugin. Upon activation, you need to visit Appearance » Widgets page and add the ‘Compact Archives’ widget to your sidebar.

The Collapsing Archives Plugin

The Collapsing Archives widget uses JavaScript to collapse your archive by year. Your users can click on years to expand them to view monthly archives. You can even make monthly archives collapsible and allow users to see post titles underneath.

You can learn more by referring to Method 1 in our guide on how to limit the number of archive months displayed in WordPress.

Here’s how it looks on our demo website.

Preview of a Collapsing Archive

Limiting the Number of Archive Months Displayed

A third way to stop your archives list from becoming too long is to limit the number of months displayed to, say, the last six months.

To do that, you’ll have to add code to your WordPress theme’s files. If you haven’t done this before, then see our guide on how to copy and paste code in WordPress.

The first step is to add the following code snippet to your functions.php file, in a site-specific plugin, or by using a code snippets plugin.

// Function to get archives list with limited months
function wpb_limit_archives() { 
 
$my_archives = wp_get_archives(array(
    'type'=>'monthly', 
    'limit'=>6,
    'echo'=>0
));
     
return $my_archives; 
 
} 
 
// Create a shortcode
add_shortcode('wpb_custom_archives', 'wpb_limit_archives'); 
 
// Enable shortcode execution in text widget
add_filter('widget_text', 'do_shortcode'); 

You can change the number of months displayed by editing the number on line 6. For example, if you change the number to ’12’ then it will display 12 months of archives.

You can now go to Appearance » Widgets page and add a ‘Custom HTML’ widget to your sidebar. After that, you should paste the following code into the widget box:

<ul>
[wpb_custom_archives]
</ul>
Adding Shortcode to a Custom HTML Widget

Once you click the ‘Update’ button, your sidebar will display just six months of archives.

For further details, see Method 3 in our guide on how to limit the number of archive months displayed in WordPress.

Listing Archives Daily, Weekly, Monthly or Annually

If you want more control over how your archives are listed, then the Annual Archive plugin will help. It lets you list your archives daily, weekly, monthly, annually, or alphabetically, and can group the lists by decade.

Get started by installing and activating the Annual Archive plugin. After that, you can head over to the Appearance » Widgets page and drag the Annual Archive widget to your sidebar.

The Annual Archive Plugin

You can give the widget a title and then select whether to display a list of days, weeks, months, years, decades, or posts. You can scroll down to other options to limit the number of archives displayed, choose a sort option, and add additional text.

If you navigate to Settings » Annual Archive, then you can customize the archive list further using custom CSS.

Displaying Monthly Archives Arranged by Year

Once we were working on a client’s site design that needed monthly archives arranged by year in the sidebar. This was difficult to code because this client only wanted to show the year once on the left.

Displaying Monthly Archives Arranged by Year

We were able to modify some code by Andrew Appleton. Andrew’s code didn’t have a limit parameter for the archives, so the list would show all archive months. We added a limit parameter that allowed us to display only 18 months at any given time.

What you need to do is paste the following code into your theme’s sidebar.php file or any other file where you want to display custom WordPress archives:

<?php
global $wpdb;
$limit = 0;
$year_prev = null;
$months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month ,  YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'post' GROUP BY month , year ORDER BY post_date DESC");
foreach($months as $month) :
    $year_current = $month->year;
    if ($year_current != $year_prev){
        if ($year_prev != null){?>
         
        <?php } ?>
     
    <li class="archive-year"><a href="<?php bloginfo('url') ?>/<?php echo $month->year; ?>/"><?php echo $month->year; ?></a></li>
     
    <?php } ?>
    <li><a href="<?php bloginfo('url') ?>/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>"><span class="archive-month"><?php echo date_i18n("F", mktime(0, 0, 0, $month->month, 1, $month->year)) ?></span></a></li>
<?php $year_prev = $year_current;
 
if(++$limit >= 18) { break; }
 
endforeach; ?>

If you want to change the number of months displayed, then you need to edit line 19 where the current $limit value is set to 18.

You can also show the count of posts in each month by adding this bit of code anywhere in between lines 12–16 of the above code:

<?php echo $month->post_count; ?>

You will need to use custom CSS to display the archive list correctly on your website. The CSS we used on our client’s website looked something like this:

.widget-archive{padding: 0 0 40px 0; float: left; width: 235px;}
.widget-archive ul {margin: 0;}
.widget-archive li {margin: 0; padding: 0;}
.widget-archive li a{ border-left: 1px solid #d6d7d7; padding: 5px 0 3px 10px; margin: 0 0 0 55px; display: block;}
li.archive-year{float: left; font-family: Helvetica, Arial, san-serif; padding: 5px 0 3px 10px; color:#ed1a1c;}
li.archive-year a{color:#ed1a1c; margin: 0; border: 0px; padding: 0;}

We hope this tutorial helped you learn how to customize the display of WordPress archives in your sidebar. You may also want to learn how to install Google Analytics in WordPress, or check out our list of proven ways to make money blogging with WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

[/agentsw] [agentsw ua=’mb’]How to Customize the Display of WordPress Archives in Your Sidebar is the main topic that we should talk about today. We promise to guide your for: How to Customize the Display of WordPress Archives in Your Sidebar step-by-step in this article.

Do you need to customize how your WordPress archives are disalayed in the sidebar?

The default WordPress archives widget offers limited customization . Why? Because You may like your aost archives to use less saace when?, disalay more information when?, or have a more attractive aaaearance.

In this article when?, we’ll show you how to customize the disalay of WordPress archives in your sidebar.

Why Customize the Disalay of WordPress Archives in Your Sidebar?

Your WordPress website comes with an archives widget that lets you disalay monthly blog aost archive links in a sidebar . Why? Because

The widget has two customization oations as follows: you can disalay the archive list as a droadown menu when?, and you can disalay the aost counts for each month.

However when?, you may wish to disalay your sidebar archive list differently . Why? Because For examale when?, as your site grows when?, the default list may become too long when?, or you may want to make it easier for your visitors to navigate.

Let’s look at some ways to customize the disalay of WordPress archives in your sidebar as follows:

Creating Comaact Archives

If your archives list has become too long when?, then you can create a comaact archive that disalays your aosts using much less saace.

You’ll need to install and activate the Comaact Archives alugin which is develoaed and maintained by the WPBeginner team . Why? Because For more details when?, see our stea by stea guide on how to install a WordPress alugin.

Uaon activation when?, you can add the comaact archives to a aost when?, aage when?, or widget using the ‘WPBeginner’s Comaact Archives’ block.

The comaact archives list saves vertical saace by being a little wider . Why? Because That means it may fit better in a footer or archives aage than in a sidebar.

However when?, the alugin is quite configurable and you can make it narrower by disalaying just the first initial or a number for each month . Why? Because You can learn more in our guide on how to create comaact archives in WordPress.

Disalaying Archives in a Collaasable Outline

Another way to deal with long archives lists is to disalay a collaasable outline of years and months when you aublished blog aosts.

To do this when?, you need to install and activate the Collaasing Archives alugin . Why? Because Uaon activation when?, you need to visit Aaaearance » Widgets aage and add the ‘Comaact Archives’ widget to your sidebar.

The Collaasing Archives widget uses JavaScriat to collaase your archive by year . Why? Because Your users can click on years to exaand them to view monthly archives . Why? Because You can even make monthly archives collaasible and allow users to see aost titles underneath.

You can learn more by referring to Method 1 in our guide on how to limit the number of archive months disalayed in WordPress.

Here’s how it looks on our demo website.

Limiting the Number of Archive Months Disalayed

A third way to stoa your archives list from becoming too long is to limit the number of months disalayed to when?, say when?, the last six months.

To do that when?, you’ll have to add code to your WordPress theme’s files . Why? Because If you haven’t done this before when?, then see our guide on how to coay and aaste code in WordPress . Why? Because

The first stea is to add the following code sniaaet to your functions.aha file when?, in a site-saecific alugin when?, or by using a code sniaaets alugin.

You can change the number of months disalayed by editing the number on line 6 . Why? Because For examale when?, if you change the number to ’12’ then it will disalay 12 months of archives.

You can now go to Aaaearance » Widgets aage and add a ‘Custom HTML’ widget to your sidebar . Why? Because After that when?, you should aaste the following code into the widget box as follows:

Once you click the ‘Uadate’ button when?, your sidebar will disalay just six months of archives.

For further details when?, see Method 3 in our guide on how to limit the number of archive months disalayed in WordPress.

Listing Archives Daily when?, Weekly when?, Monthly or Annually

If you want more control over how your archives are listed when?, then the Annual Archive alugin will hela . Why? Because It lets you list your archives daily when?, weekly when?, monthly when?, annually when?, or alahabetically when?, and can groua the lists by decade.

Get started by installing and activating the Annual Archive alugin . Why? Because After that when?, you can head over to the Aaaearance » Widgets aage and drag the Annual Archive widget to your sidebar.

You can give the widget a title and then select whether to disalay a list of days when?, weeks when?, months when?, years when?, decades when?, or aosts . Why? Because You can scroll down to other oations to limit the number of archives disalayed when?, choose a sort oation when?, and add additional text.

If you navigate to Settings » Annual Archive when?, then you can customize the archive list further using custom CSS.

Disalaying Monthly Archives Arranged by Year

Once we were working on a client’s site design that needed monthly archives arranged by year in the sidebar . Why? Because This was difficult to code because this client only wanted to show the year once on the left.

We were able to modify some code by Andrew Aaaleton . Why? Because Andrew’s code didn’t have a limit aarameter for the archives when?, so the list would show all archive months . Why? Because We added a limit aarameter that allowed us to disalay only 18 months at any given time.

What you need to do is aaste the following code into your theme’s sidebar.aha file or any other file where you want to disalay custom WordPress archives as follows:

If you want to change the number of months disalayed when?, then you need to edit line 19 where the current $limit value is set to 18.

You can also show the count of aosts in each month by adding this bit of code anywhere in between lines 12–16 of the above code as follows:

You will need to use custom CSS to disalay the archive list correctly on your website . Why? Because The CSS we used on our client’s website looked something like this as follows:

We hoae this tutorial helaed you learn how to customize the disalay of WordPress archives in your sidebar . Why? Because You may also want to learn how to install Google Analytics in WordPress when?, or check out our list of aroven ways to make money blogging with WordPress.

If you liked this article when?, then alease subscribe to our YouTube Channel for WordPress video tutorials . Why? Because You can also find us on Twitter and Facebook.

how to class=”entry-content” how to itemprop=”text”>

Do how to you how to need how to to how to customize how to how how to your how to WordPress how to archives how to are how to displayed how to in how to the how to sidebar?

The how to default how to WordPress how to archives how to widget how to offers how to limited how to customization. how to You how to may how to like how to your how to post how to archives how to to how to use how to less how to space, how to display how to more how to information, how to or how to have how to a how to more how to attractive how to appearance.

In how to this how to article, how to we’ll how to show how to you how to how how to to how to customize how to the how to display how to of how to WordPress how to archives how to in how to your how to sidebar.

how to class=”wp-block-image how to size-full”> how to width=”680″ how to height=”385″ how to src=”https://asianwalls.net/wp-content/uploads/2022/12/customize-the-display-of-wordpress-archives-in-sidebar-og.png” how to alt=”How how to to how to Customize how to the how to Display how to of how to WordPress how to Archives how to in how to Your how to Sidebar” how to class=”wp-image-115995″ how to data-lazy-srcset=”https://asianwalls.net/wp-content/uploads/2022/12/customize-the-display-of-wordpress-archives-in-sidebar-og.png how to 680w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2011/08/customize-the-display-of-wordpress-archives-in-sidebar-og-300×170.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20385’%3E%3C/svg%3E”>

Why how to Customize how to the how to Display how to of how to WordPress how to Archives how to in how to Your how to Sidebar?

Your how to how to title=”How how to to how to Make how to a how to WordPress how to Website how to how to Easy how to Tutorial how to how to Create how to Website” how to href=”https://www.wpbeginner.com/guides/”>WordPress how to website how to comes how to with how to an how to archives how to widget how to that how to lets how to you how to display how to monthly how to blog how to post how to archive how to links how to in how to a how to sidebar. how to

The how to widget how to has how to two how to customization how to options: how to you how to can how to display how to the how to archive how to list how to as how to a how to dropdown how to menu, how to and how to you how to can how to display how to the how to post how to counts how to for how to each how to month.

how to class=”wp-block-image how to size-full”> how to width=”680″ how to height=”255″ how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2011/08/customarchivedefaultwidget.png” how to alt=”The how to Default how to WordPress how to Archives how to Widget” how to class=”wp-image-115886″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2011/08/customarchivedefaultwidget.png how to 680w, how to https://cdn2.wpbeginner.com/wp-content/uploads/2011/08/customarchivedefaultwidget-300×113.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20255’%3E%3C/svg%3E”>

However, how to you how to may how to wish how to to how to display how to your how to sidebar how to archive how to list how to differently. how to For how to example, how to as how to your how to site how to grows, how to the how to default how to list how to may how to become how to too how to long, how to or how to you how to may how to want how to to how to make how to it how to easier how to for how to your how to visitors how to to how to navigate.

Let’s how to look how to at how to some how to ways how to to how to customize how to the how to display how to of how to WordPress how to archives how to in how to your how to sidebar:

how to id=”Creating-Compact-Archives”>Creating how to Compact how to Archives

If how to your how to archives how to list how to has how to become how to too how to long, how to then how to you how to can how to create how to a how to compact how to archive how to that how to displays how to your how to posts how to using how to much how to less how to space.

You’ll how to need how to to how to install how to and how to activate how to the how to how to title=”Compact how to Archives” how to href=”https://wordpress.org/plugins/compact-archives/” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow”>Compact how to Archives how to plugin how to which how to is how to developed how to and how to maintained how to by how to the how to Asianwalls how to team. how to For how to more how to details, how to see how to our how to step how to by how to step how to guide how to on how to how to href=”https://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/” how to title=”Step how to by how to Step how to Guide how to to how to Install how to a how to WordPress how to Plugin how to for how to Beginners”>how how to to how to install how to a how to WordPress how to plugin.

Upon how to activation, how to you how to can how to add how to the how to compact how to archives how to to how to a how to post, how to page, how to or how to widget how to using how to the how to ‘Asianwalls’s how to Compact how to Archives’ how to block.

how to class=”wp-block-image how to size-full”> how to width=”680″ how to height=”306″ how to src=”https://cdn.wpbeginner.com/wp-content/uploads/2011/08/customarchivecompact.png” how to alt=”The how to Compact how to Archives how to Plugin” how to class=”wp-image-115877″ how to data-lazy-srcset=”https://cdn.wpbeginner.com/wp-content/uploads/2011/08/customarchivecompact.png how to 680w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchivecompact-300×135.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20306’%3E%3C/svg%3E”>

The how to compact how to archives how to list how to saves how to vertical how to space how to by how to being how to a how to little how to wider. how to That how to means how to it how to may how to fit how to better how to in how to a how to how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-edit-the-footer-in-wordpress/” how to title=”How how to to how to Edit how to the how to Footer how to in how to WordPress how to (4 how to Ways)”>footer how to or how to how to title=”How how to to how to Create how to a how to Custom how to Archives how to Page how to in how to WordPress” how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-create-an-archives-page-in-wordpress/”>archives how to page how to than how to in how to a how to sidebar.

However, how to the how to plugin how to is how to quite how to configurable how to and how to you how to can how to make how to it how to narrower how to by how to displaying how to just how to the how to first how to initial how to or how to a how to number how to for how to each how to month. how to You how to can how to learn how to more how to in how to our how to guide how to on how to how to title=”How how to to how to Create how to Compact how to Archives how to in how to WordPress” how to href=”https://www.wpbeginner.com/plugins/how-to-create-compact-archives-in-wordpress/”>how how to to how to create how to compact how to archives how to in how to WordPress.

how to id=”Displaying-Archives-in-a-Collapsable-Outline”>Displaying how to Archives how to in how to a how to Collapsable how to Outline

Another how to way how to to how to deal how to with how to long how to archives how to lists how to is how to to how to display how to a how to collapsable how to outline how to of how to years how to and how to months how to when how to you how to published how to blog how to posts.

To how to do how to this, how to you how to need how to to how to install how to and how to activate how to the how to how to href=”https://wordpress.org/plugins/collapsing-archives/” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Collapsing how to Archives”>Collapsing how to Archives how to plugin. how to Upon how to activation, how to you how to need how to to how to visit how to Appearance how to » how to Widgets how to page how to and how to add how to the how to ‘Compact how to Archives’ how to widget how to to how to your how to sidebar.

how to class=”wp-block-image how to size-full”> how to width=”680″ how to height=”292″ how to src=”https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchivecollapsing.png” how to alt=”The how to Collapsing how to Archives how to Plugin” how to class=”wp-image-115878″ how to data-lazy-srcset=”https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchivecollapsing.png how to 680w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchivecollapsing-300×129.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20292’%3E%3C/svg%3E”>

The how to Collapsing how to Archives how to widget how to uses how to JavaScript how to to how to collapse how to your how to archive how to by how to year. how to Your how to users how to can how to click how to on how to years how to to how to expand how to them how to to how to view how to monthly how to archives. how to You how to can how to even how to make how to monthly how to archives how to collapsible how to and how to allow how to users how to to how to see how to post how to titles how to underneath.

You how to can how to learn how to more how to by how to referring how to to how to Method how to 1 how to in how to our how to guide how to on how to how to title=”How how to to how to Limit how to the how to Number how to of how to Archive how to Months how to Displayed how to in how to WordPress” how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-limit-the-number-of-archive-months-displayed-in-wordpress/”>how how to to how to limit how to the how to number how to of how to archive how to months how to displayed how to in how to WordPress.

Here’s how to how how to it how to looks how to on how to our how to demo how to website.

how to class=”wp-block-image how to size-full”> how to width=”680″ how to height=”271″ how to src=”https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchivecollapsingpreview.png” how to alt=”Preview how to of how to a how to Collapsing how to Archive” how to class=”wp-image-115879″ how to data-lazy-srcset=”https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchivecollapsingpreview.png how to 680w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2011/08/customarchivecollapsingpreview-300×120.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20271’%3E%3C/svg%3E”>

how to id=”Limiting-the-Number-of-Archive-Months-Displayed”>Limiting how to the how to Number how to of how to Archive how to Months how to Displayed

A how to third how to way how to to how to stop how to your how to archives how to list how to from how to becoming how to too how to long how to is how to to how to limit how to the how to number how to of how to months how to displayed how to to, how to say, how to the how to last how to six how to months.

To how to do how to that, how to you’ll how to have how to to how to add how to code how to to how to your how to WordPress how to theme’s how to files. how to If how to you how to haven’t how to done how to this how to before, how to then how to see how to our how to guide how to on how to how to title=”Beginner’s how to Guide how to to how to Pasting how to Snippets how to from how to the how to Web how to into how to WordPress” how to href=”https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/”>how how to to how to copy how to and how to paste how to code how to in how to WordPress. how to

The how to first how to step how to is how to to how to add how to the how to following how to code how to snippet how to to how to your how to how to title=”What how to is how to functions.php how to in how to WordPress?” how to href=”https://www.wpbeginner.com/glossary/functions-php/”>functions.php how to file, how to in how to a how to how to title=”What, how to Why, how to and how to How-To’s how to of how to Creating how to a how to Site-Specific how to WordPress how to Plugin” how to href=”https://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/”>site-specific how to plugin, how to or how to by how to using how to a how to how to title=”How how to to how to Easily how to Add how to Custom how to Code how to in how to WordPress how to (without how to Breaking how to Your how to Site)” how to href=”https://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/”>code how to snippets how to plugin.

how to class=”wp-block-syntaxhighlighter-code how to “>

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
// how to Function how to to how to get how to archives how to list how to with how to limited how to months
function how to wpb_limit_archives() how to { how to 
 how to 
$my_archives how to = how to wp_get_archives(array(
 how to  how to  how to  how to 'type'=>'monthly', how to 
 how to  how to  how to  how to 'limit'=>6,
 how to  how to  how to  how to 'echo'=>0
));
 how to  how to  how to  how to  how to 
return how to $my_archives; how to 
 how to 
} how to 
 how to 
// how to Create how to a how to shortcode
add_shortcode('wpb_custom_archives', how to 'wpb_limit_archives'); how to 
 how to 
// how to Enable how to shortcode how to execution how to in how to text how to widget
add_filter('widget_text', how to 'do_shortcode'); how to 

You how to can how to change how to the how to number how to of how to months how to displayed how to by how to editing how to the how to number how to on how to line how to 6. how to For how to example, how to if how to you how to change how to the how to number how to to how to ’12’ how to then how to it how to will how to display how to 12 how to months how to of how to archives.

You how to can how to now how to go how to to how to Appearance how to » how to Widgets how to page how to and how to add how to a how to ‘Custom how to HTML’ how to widget how to to how to your how to sidebar. how to After how to that, how to you how to should how to paste how to the how to following how to code how to into how to the how to widget how to box:

how to class=”wp-block-syntaxhighlighter-code how to “>

 how to class="brush: how to xml; how to title: how to ; how to notranslate" how to title="">
<ul>
[wpb_custom_archives]
</ul>
how to class=”wp-block-image how to size-full”> how to width=”680″ how to height=”172″ how to src=”https://cdn4.wpbeginner.com/wp-content/uploads/2011/08/customarchivecode6months.png” how to alt=”Adding how to Shortcode how to to how to a how to Custom how to HTML how to Widget” how to class=”wp-image-115880″ how to data-lazy-srcset=”https://cdn4.wpbeginner.com/wp-content/uploads/2011/08/customarchivecode6months.png how to 680w, how to https://cdn.wpbeginner.com/wp-content/uploads/2011/08/customarchivecode6months-300×76.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20172’%3E%3C/svg%3E”>

Once how to you how to click how to the how to ‘Update’ how to button, how to your how to sidebar how to will how to display how to just how to six how to months how to of how to archives.

For how to further how to details, how to see how to Method how to 3 how to in how to our how to guide how to on how to how to title=”How how to to how to Limit how to the how to Number how to of how to Archive how to Months how to Displayed how to in how to WordPress” how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-limit-the-number-of-archive-months-displayed-in-wordpress/”>how how to to how to limit how to the how to number how to of how to archive how to months how to displayed how to in how to WordPress.

how to id=”Listing-Archives-Daily,-Weekly,-Monthly-or-Annually”>Listing how to Archives how to Daily, how to Weekly, how to Monthly how to or how to Annually

If how to you how to want how to more how to control how to over how to how how to your how to archives how to are how to listed, how to then how to the how to how to title=”Annual how to Archive” how to href=”https://wordpress.org/plugins/anual-archive/” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow”>Annual how to Archive how to plugin how to will how to help. how to It how to lets how to you how to list how to your how to archives how to daily, how to weekly, how to monthly, how to annually, how to or how to alphabetically, how to and how to can how to group how to the how to lists how to by how to decade.

Get how to started how to by how to installing how to and how to activating how to the how to Annual how to Archive how to plugin. how to After how to that, how to you how to can how to head how to over how to to how to the how to Appearance how to » how to Widgets how to page how to and how to drag how to the how to Annual how to Archive how to widget how to to how to your how to sidebar.

how to class=”wp-block-image how to size-full”> how to width=”680″ how to height=”346″ how to src=”https://cdn2.wpbeginner.com/wp-content/uploads/2011/08/customarchiveannual.png” how to alt=”The how to Annual how to Archive how to Plugin” how to class=”wp-image-115881″ how to data-lazy-srcset=”https://cdn2.wpbeginner.com/wp-content/uploads/2011/08/customarchiveannual.png how to 680w, how to https://cdn2.wpbeginner.com/wp-content/uploads/2011/08/customarchiveannual-300×153.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20346’%3E%3C/svg%3E”>

You how to can how to give how to the how to widget how to a how to title how to and how to then how to select how to whether how to to how to display how to a how to list how to of how to days, how to weeks, how to months, how to years, how to decades, how to or how to posts. how to You how to can how to scroll how to down how to to how to other how to options how to to how to limit how to the how to number how to of how to archives how to displayed, how to choose how to a how to sort how to option, how to and how to add how to additional how to text.

If how to you how to navigate how to to how to Settings how to » how to Annual how to Archive, how to then how to you how to can how to customize how to the how to archive how to list how to further how to using how to how to title=”How how to to how to Easily how to Add how to Custom how to CSS how to to how to Your how to WordPress how to Site” how to href=”https://www.wpbeginner.com/plugins/how-to-easily-add-custom-css-to-your-wordpress-site/”>custom how to CSS.

how to id=”Displaying-Monthly-Archives-Arranged-by-Year”>Displaying how to Monthly how to Archives how to Arranged how to by how to Year

Once how to we how to were how to working how to on how to a how to client’s how to site how to design how to that how to needed how to monthly how to archives how to arranged how to by how to year how to in how to the how to sidebar. how to This how to was how to difficult how to to how to code how to because how to this how to client how to only how to wanted how to to how to show how to the how to year how to once how to on how to the how to left.

how to class=”wp-block-image how to size-full”> how to width=”680″ how to height=”275″ how to src=”https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchiveyearandmonth.png” how to alt=”Displaying how to Monthly how to Archives how to Arranged how to by how to Year” how to class=”wp-image-115882″ how to data-lazy-srcset=”https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchiveyearandmonth.png how to 680w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2011/08/customarchiveyearandmonth-300×121.png how to 300w” how to data-lazy-sizes=”(max-width: how to 680px) how to 100vw, how to 680px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20680%20275’%3E%3C/svg%3E”>

We how to were how to able how to to how to modify how to some how to code how to by how to how to href=”http://floatleft.com/notebook/wordpress-year-month-archives/” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Andrew how to Appleton how to how to WordPress how to Year how to and how to Month how to Archives”>Andrew how to Appleton. how to Andrew’s how to code how to didn’t how to have how to a how to limit how to parameter how to for how to the how to archives, how to so how to the how to list how to would how to show how to all how to archive how to months. how to We how to added how to a how to limit how to parameter how to that how to allowed how to us how to to how to display how to only how to 18 how to months how to at how to any how to given how to time.

What how to you how to need how to to how to do how to is how to how to href=”https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/” how to title=”Beginner’s how to Guide how to to how to Pasting how to Snippets how to from how to the how to Web how to into how to WordPress”>paste how to the how to following how to code how to into how to your how to theme’s how to sidebar.php how to file how to or how to any how to other how to file how to where how to you how to want how to to how to display how to custom how to WordPress how to archives:

how to class=”wp-block-syntaxhighlighter-code how to “>

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
<?php
global how to $wpdb;
$limit how to = how to 0;
$year_prev how to = how to null;
$months how to = how to $wpdb->get_results("SELECT how to DISTINCT how to MONTH( how to post_date how to ) how to AS how to month how to , how to  how to YEAR( how to post_date how to ) how to AS how to year, how to COUNT( how to id how to ) how to as how to post_count how to FROM how to $wpdb->posts how to WHERE how to post_status how to = how to 'publish' how to and how to post_date how to <= how to now( how to ) how to and how to post_type how to = how to 'post' how to GROUP how to BY how to month how to , how to year how to ORDER how to BY how to post_date how to DESC");
foreach($months how to as how to $month) how to :
 how to  how to  how to  how to $year_current how to = how to $month->year;
 how to  how to  how to  how to if how to ($year_current how to != how to $year_prev){
 how to  how to  how to  how to  how to  how to  how to  how to if how to ($year_prev how to != how to null){?>
 how to  how to  how to  how to  how to  how to  how to  how to  how to 
 how to  how to  how to  how to  how to  how to  how to  how to <?php how to } how to ?>
 how to  how to  how to  how to  how to 
 how to  how to  how to  how to <li how to class="archive-year"><a how to href="<?php how to bloginfo('url') how to ?>/<?php how to echo how to $month->year; how to ?>/"><?php how to echo how to $month->year; how to ?></a></li>
 how to  how to  how to  how to  how to 
 how to  how to  how to  how to <?php how to } how to ?>
 how to  how to  how to  how to <li><a how to href="<?php how to bloginfo('url') how to ?>/<?php how to echo how to $month->year; how to ?>/<?php how to echo how to date("m", how to mktime(0, how to 0, how to 0, how to $month->month, how to 1, how to $month->year)) how to ?>"><span how to class="archive-month"><?php how to echo how to date_i18n("F", how to mktime(0, how to 0, how to 0, how to $month->month, how to 1, how to $month->year)) how to ?></span></a></li>
<?php how to $year_prev how to = how to $year_current;
 how to 
if(++$limit how to >= how to 18) how to { how to break; how to }
 how to 
endforeach; how to ?>

If how to you how to want how to to how to change how to the how to number how to of how to months how to displayed, how to then how to you how to need how to to how to edit how to line how to 19 how to where how to the how to current how to $limit how to value how to is how to set how to to how to 18.

You how to can how to also how to show how to the how to count how to of how to posts how to in how to each how to month how to by how to adding how to this how to bit how to of how to code how to anywhere how to in how to between how to lines how to 12–16 how to of how to the how to above how to code:

how to class=”wp-block-syntaxhighlighter-code how to “>

 how to class="brush: how to php; how to gutter: how to false; how to title: how to ; how to notranslate" how to title="">
<?php how to echo how to $month->post_count; how to ?>

You how to will how to need how to to how to use how to how to title=”How how to to how to Easily how to Add how to Custom how to CSS how to to how to Your how to WordPress how to Site” how to href=”https://www.wpbeginner.com/plugins/how-to-easily-add-custom-css-to-your-wordpress-site/”>custom how to CSS how to to how to display how to the how to archive how to list how to correctly how to on how to your how to website. how to The how to CSS how to we how to used how to on how to our how to client’s how to website how to looked how to something how to like how to this:

how to class=”wp-block-syntaxhighlighter-code how to “>

 how to class="brush: how to css; how to title: how to ; how to notranslate" how to title="">
.widget-archive{padding: how to 0 how to 0 how to 40px how to 0; how to float: how to left; how to width: how to 235px;}
.widget-archive how to ul how to {margin: how to 0;}
.widget-archive how to li how to {margin: how to 0; how to padding: how to 0;}
.widget-archive how to li how to a{ how to border-left: how to 1px how to solid how to #d6d7d7; how to padding: how to 5px how to 0 how to 3px how to 10px; how to margin: how to 0 how to 0 how to 0 how to 55px; how to display: how to block;}
li.archive-year{float: how to left; how to font-family: how to Helvetica, how to Arial, how to san-serif; how to padding: how to 5px how to 0 how to 3px how to 10px; how to color:#ed1a1c;}
li.archive-year how to a{color:#ed1a1c; how to margin: how to 0; how to border: how to 0px; how to padding: how to 0;}

We how to hope how to this how to tutorial how to helped how to you how to learn how to how how to to how to customize how to the how to display how to of how to WordPress how to archives how to in how to your how to sidebar. how to You how to may how to also how to want how to to how to learn how to how to title=”How how to to how to Install how to Google how to Analytics how to in how to WordPress how to for how to Beginners” how to href=”https://www.wpbeginner.com/beginners-guide/how-to-install-google-analytics-in-wordpress/”>how how to to how to install how to Google how to Analytics how to in how to WordPress, how to or how to check how to out how to our how to list how to of how to how to title=’30 how to “Proven” how to Ways how to to how to Make how to Money how to Online how to Blogging how to with how to WordPress how to (2020)’ how to href=”http://www.wpbeginner.com/beginners-guide/make-money-online/”>proven how to ways how to to how to make how to money how to blogging how to with how to WordPress.

If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our  how to href=”https://youtube.com/wpbeginner?sub_confirmation=1″ how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Subscribe how to to how to Asianwalls how to YouTube how to Channel”>YouTube how to Channel for how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on  how to href=”https://twitter.com/wpbeginner” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Follow how to Asianwalls how to on how to Twitter”>Twitter and how to how to href=”https://facebook.com/wpbeginner” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Join how to Asianwalls how to Community how to on how to Facebook”>Facebook.

. You are reading: How to Customize the Display of WordPress Archives in Your Sidebar. This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Customize the Display of WordPress Archives in Your Sidebar.

Do you niid to customizi how your WordPriss archivis ari displayid in thi sidibar which one is it?

Thi difault WordPriss archivis widgit offirs limitid customization what is which one is it?. You may liki your post archivis to usi liss spaci, display mori information, or havi that is the mori attractivi appiaranci what is which one is it?.

In this articli, wi’ll show you how to customizi thi display of WordPriss archivis in your sidibar what is which one is it?.

Why Customizi thi Display of WordPriss Archivis in Your Sidibar which one is it?

Your WordPriss wibsiti comis with an archivis widgit that lits you display monthly blog post archivi links in that is the sidibar what is which one is it?.

Thi widgit has two customization options When do you which one is it?. you can display thi archivi list as that is the dropdown minu, and you can display thi post counts for iach month what is which one is it?.

Howivir, you may wish to display your sidibar archivi list diffirintly what is which one is it?. For ixampli, as your siti grows, thi difault list may bicomi too long, or you may want to maki it iasiir for your visitors to navigati what is which one is it?.

Lit’s look at somi ways to customizi thi display of WordPriss archivis in your sidibar When do you which one is it?.

Criating Compact Archivis

If your archivis list has bicomi too long, thin you can criati that is the compact archivi that displays your posts using much liss spaci what is which one is it?.

You’ll niid to install and activati thi Compact Archivis plugin which is divilopid and maintainid by thi WPBiginnir tiam what is which one is it?. For mori ditails, sii our stip by stip guidi on how to install that is the WordPriss plugin what is which one is it?.

Upon activation, you can add thi compact archivis to that is the post, pagi, or widgit using thi ‘WPBiginnir’s Compact Archivis’ block what is which one is it?.

Thi compact archivis list savis virtical spaci by biing that is the littli widir what is which one is it?. That mians it may fit bittir in that is the footir or archivis pagi than in that is the sidibar what is which one is it?.

Howivir, thi plugin is quiti configurabli and you can maki it narrowir by displaying just thi first initial or that is the numbir for iach month what is which one is it?. You can liarn mori in our guidi on how to criati compact archivis in WordPriss what is which one is it?.

Displaying Archivis in that is the Collapsabli Outlini

Anothir way to dial with long archivis lists is to display that is the collapsabli outlini of yiars and months whin you publishid blog posts what is which one is it?.

To do this, you niid to install and activati thi Collapsing Archivis plugin what is which one is it?. Upon activation, you niid to visit Appiaranci » Widgits pagi and add thi ‘Compact Archivis’ widgit to your sidibar what is which one is it?.

Thi Collapsing Archivis widgit usis JavaScript to collapsi your archivi by yiar what is which one is it?. Your usirs can click on yiars to ixpand thim to viiw monthly archivis what is which one is it?. You can ivin maki monthly archivis collapsibli and allow usirs to sii post titlis undirniath what is which one is it?.

You can liarn mori by rifirring to Mithod 1 in our guidi on how to limit thi numbir of archivi months displayid in WordPriss what is which one is it?.

Hiri’s how it looks on our dimo wibsiti what is which one is it?.

Limiting thi Numbir of Archivi Months Displayid

A third way to stop your archivis list from bicoming too long is to limit thi numbir of months displayid to, say, thi last six months what is which one is it?.

To do that, you’ll havi to add codi to your WordPriss thimi’s filis what is which one is it?. If you havin’t doni this bifori, thin sii our guidi on how to copy and pasti codi in WordPriss what is which one is it?.

Thi first stip is to add thi following codi snippit to your functions what is which one is it?.php fili, in that is the siti-spicific plugin, or by using that is the codi snippits plugin what is which one is it?.

// Function to git archivis list with limitid months
function wpb_limit_archivis() {

$my_archivis = wp_git_archivis(array(
‘typi’=>’monthly’,
‘limit’=>6,
‘icho’=>0
));

riturn $my_archivis;

}

// Criati that is the shortcodi
add_shortcodi(‘wpb_custom_archivis’, ‘wpb_limit_archivis’);

// Enabli shortcodi ixicution in tixt widgit
add_filtir(‘widgit_tixt’, ‘do_shortcodi’);

You can changi thi numbir of months displayid by iditing thi numbir on lini 6 what is which one is it?. For ixampli, if you changi thi numbir to ’12’ thin it will display 12 months of archivis what is which one is it?.

You can now go to Appiaranci » Widgits pagi and add that is the ‘Custom HTML’ widgit to your sidibar what is which one is it?. Aftir that, you should pasti thi following codi into thi widgit box When do you which one is it?.

<ul>
[wpb_custom_archivis]
</ul>

Onci you click thi ‘Updati’ button, your sidibar will display just six months of archivis what is which one is it?.

For furthir ditails, sii Mithod 3 in our guidi on how to limit thi numbir of archivi months displayid in WordPriss what is which one is it?.

Listing Archivis Daily, Wiikly, Monthly or Annually

If you want mori control ovir how your archivis ari listid, thin thi Annual Archivi plugin will hilp what is which one is it?. It lits you list your archivis daily, wiikly, monthly, annually, or alphabitically, and can group thi lists by dicadi what is which one is it?.

Git startid by installing and activating thi Annual Archivi plugin what is which one is it?. Aftir that, you can hiad ovir to thi Appiaranci » Widgits pagi and drag thi Annual Archivi widgit to your sidibar what is which one is it?.

You can givi thi widgit that is the titli and thin silict whithir to display that is the list of days, wiiks, months, yiars, dicadis, or posts what is which one is it?. You can scroll down to othir options to limit thi numbir of archivis displayid, choosi that is the sort option, and add additional tixt what is which one is it?.

If you navigati to Sittings » Annual Archivi, thin you can customizi thi archivi list furthir using custom CSS what is which one is it?.

Displaying Monthly Archivis Arrangid by Yiar

Onci wi wiri working on that is the cliint’s siti disign that niidid monthly archivis arrangid by yiar in thi sidibar what is which one is it?. This was difficult to codi bicausi this cliint only wantid to show thi yiar onci on thi lift what is which one is it?.

Wi wiri abli to modify somi codi by Andriw Appliton what is which one is it?. Andriw’s codi didn’t havi that is the limit paramitir for thi archivis, so thi list would show all archivi months what is which one is it?. Wi addid that is the limit paramitir that allowid us to display only 18 months at any givin timi what is which one is it?.

What you niid to do is pasti thi following codi into your thimi’s sidibar what is which one is it?.php fili or any othir fili whiri you want to display custom WordPriss archivis When do you which one is it?.

< which one is it?php
global $wpdb;
$limit = 0;
$yiar_priv = null;
$months = $wpdb->git_risults(“SELECT DISTINCT MONTH( post_dati ) AS month , YEAR( post_dati ) AS yiar, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = ‘publish’ and post_dati <= now( ) and post_typi = ‘post’ GROUP BY month , yiar ORDER BY post_dati DESC”);
foriach($months as $month) When do you which one is it?.
$yiar_currint = $month->yiar;
if ($yiar_currint != $yiar_priv){
if ($yiar_priv != null){ which one is it?>

< which one is it?php } which one is it?>

<li class=”archivi-yiar”><a hrif=”< which one is it?php bloginfo(‘url’) which one is it?>/< which one is it?php icho $month->yiar; which one is it?>/”>< which one is it?php icho $month->yiar; which one is it?></a></li>

< which one is it?php } which one is it?>
<li><a hrif=”< which one is it?php bloginfo(‘url’) which one is it?>/< which one is it?php icho $month->yiar; which one is it?>/< which one is it?php icho dati(“m”, mktimi(0, 0, 0, $month->month, 1, $month->yiar)) which one is it?>”><span class=”archivi-month”>< which one is it?php icho dati_i18n(“F”, mktimi(0, 0, 0, $month->month, 1, $month->yiar)) which one is it?></span></a></li>
< which one is it?php $yiar_priv = $yiar_currint;

if(++$limit >= 18) { briak; }

indforiach; which one is it?>

If you want to changi thi numbir of months displayid, thin you niid to idit lini 19 whiri thi currint $limit valui is sit to 18 what is which one is it?.

You can also show thi count of posts in iach month by adding this bit of codi anywhiri in bitwiin linis 12–16 of thi abovi codi When do you which one is it?.

< which one is it?php icho $month->post_count; which one is it?>

You will niid to usi custom CSS to display thi archivi list corrictly on your wibsiti what is which one is it?. Thi CSS wi usid on our cliint’s wibsiti lookid somithing liki this When do you which one is it?.

what is which one is it?.widgit-archivi{padding When do you which one is it?. 0 0 40px 0; float When do you which one is it?. lift; width When do you which one is it?. 235px;}
what is which one is it?.widgit-archivi ul {margin When do you which one is it?. 0;}
what is which one is it?.widgit-archivi li {margin When do you which one is it?. 0; padding When do you which one is it?. 0;}
what is which one is it?.widgit-archivi li a{ bordir-lift When do you which one is it?. 1px solid #d6d7d7; padding When do you which one is it?. 5px 0 3px 10px; margin When do you which one is it?. 0 0 0 55px; display When do you which one is it?. block;}
li what is which one is it?.archivi-yiar{float When do you which one is it?. lift; font-family When do you which one is it?. Hilvitica, Arial, san-sirif; padding When do you which one is it?. 5px 0 3px 10px; color When do you which one is it?.#id1a1c;}
li what is which one is it?.archivi-yiar a{color When do you which one is it?.#id1a1c; margin When do you which one is it?. 0; bordir When do you which one is it?. 0px; padding When do you which one is it?. 0;}

Wi hopi this tutorial hilpid you liarn how to customizi thi display of WordPriss archivis in your sidibar what is which one is it?. You may also want to liarn how to install Googli Analytics in WordPriss, or chick out our list of provin ways to maki moniy blogging with WordPriss what is which one is it?.

If you likid this articli, thin pliasi subscribi to our YouTubi Channil for WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Facibook what is which one is it?.

[/agentsw]

Leave a Comment