WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/get archives


This function has been deprecated. That means it has been replaced by a new function or is no longer supported, and may be removed from future versions. All code that uses this function should be converted to use its replacement if one exists. See also wp-includes/deprecated.php. Use any of these functions instead.

Contents

Description

Displays a list of links to date-based archives. This tag can be used anywhere within a template.

Replace With

Usage

 <?php get_archives$type$limit$format$before$after$show_post_count ); ?> 

Parameters

type 
(string) The type of archive list to display. Defaults to WordPress setting (defaults to 'monthly' in 1.5). Valid values:
  • 'monthly' (Default)
  • 'daily'
  • 'weekly'
  • 'postbypost'
limit 
(integer) Number of archives to get. Use '' for no limit.
format 
(string) Format for the archive list. Valid values:
  • 'html' - In HTML list (<li>) tags. This is the default.
  • 'option' - In select or dropdown option (<option>) tags.
  • 'link' - Within link (<link>) tags.
  • 'custom' - Custom list.
before 
(string) Text to place before the link when using 'custom' or 'html' for format option. Defaults to ''.
after 
(string) Text to place after the link when using 'custom' or 'html' for format option. Defaults to ''.
show_post_count 
(boolean) Display number of posts in an archive (TRUE) or do not (FALSE). For use when type is set to 'monthly'. Defaults to FALSE.

Examples

Default Usage

Displays archive links using defaults.

<?php get_archives(); ?>


By Month with Post Count

Displays all archives by month in an unordered list, with count of posts by month.

<ul>
<?php get_archives('monthly', '', 'html', '', '', TRUE); ?>
</ul>


Displays Last 10 Posts In A List

Displays a non-bulleted list of the last 10 posts separated by line breaks.

<?php get_archives('postbypost', '10', 'custom', '', '<br />'); ?>

Using Dropdown List

Displays monthly archives in a dropdown list; the use of javascript is required to have an archive selection open on the page.

<form id="archiveform" action="">
<select name="archive_chrono" onchange="window.location =
(document.forms.archiveform.archive_chrono[document.forms.archiveform.archive_chrono.selectedIndex].value);">
<option value=''>Select Month</option>
<?php get_archives('monthly','','option'); ?>
</select>
</form>

You also can use piece of code below, that works better than the example above. It shows the months list, including the number of posts/month.

 <select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
 <option value="">Select month</option>
 <?php get_archives('monthly',,'option',,,'TRUE'); ?>
 </select>

List of Limited Number of Recent Posts

Displays a custom number of recent posts in an unordered list.

 <ul><?php get_archives('postbypost','10','custom','<li>','</li>'); ?></ul>

Change Log

Related

List & Dropdown Functions

See also index of Function Reference and index of Template Tags.