The get_archives() WordPress PHP function retrieves a list of archives.
Usage
get_archives($type='', $limit='', $format='html', $before='', $after='', $show_post_count=false);
Parameters
$type
(string) Optional – The archive type. Default:''
$limit
(string) Optional – The number of archives to display. Default:''
$format
(string) Optional – The output format. Default:'html'
$before
(string) Optional – Text to display before the link. Default:''
$after
(string) Optional – Text to display after the link. Default:''
$show_post_count
(bool) Optional – Whether to display the post count. Default:false
More information
See WordPress Developer Resources: get_archives
Examples
Display Monthly Archives
This example shows how to display monthly archives.
// Display monthly archives get_archives('monthly');
Display Yearly Archives with Post Count
This example shows how to display yearly archives with the number of posts in each year.
// Display yearly archives with post count get_archives('yearly', '', 'html', '', '', true);
Display Top 5 Daily Archives
This example shows how to display the top 5 daily archives.
// Display top 5 daily archives get_archives('daily', '5');
Display Archives in a Dropdown
This example shows how to display archives in a dropdown format.
// Display archives in a dropdown format get_archives('monthly', '', 'option');
Display Archives with Custom Text
This example shows how to display archives with custom text before and after the link.
// Display archives with custom text get_archives('monthly', '', 'html', '<strong>', '</strong>');