How to Use the WordPress Post Archives Template Tag

By Lisa Sabin-Wilson

The <?php wp_get_archives(); ?> template tag displays the WordPress blog post archives in a number of ways, using the parameters and values below. Values that appear in bold are the default values set by WordPress. Here are just a few examples of what you can produce with this template tag:

  • Display the titles of the last 15 posts you’ve made to your blog.

  • Display the titles of the posts you’ve made in the past ten days.

  • Display a monthly list of archives.

    Parameter and Type Possible Values Example
    type
    (string)
    Determines the type of archive to display.
    monthly
    daily
    weekly
    postbypost
    <?php wp_get_archives
    type=postbypost); ?>
    Displays the titles of the most recent blog posts.
    format
    (string)
    Formats the display of the links in the archive list.
    html — Surrounds the links with
    <li> </li> tags.
    option — Places archive list in
    drop-down menu format.
    link — Surrounds the links with
    <link> </link> tags.
    custom — Use your own HTML tags, using the before and after
    parameters.
    <?php wp_get_archives(format=html); ?>
    Displays the list of archive links where each link is surrounded by
    the <li> </li> HTML
    tags.
    limit
    (integer)
    Limits the number of archives to display.
    If no value, all are displayed. <?php wp_get_archives(limit=10); ?>
    Displays the last ten archives in a list.
    before
    (string)
    Places text or formatting before the link in the archive list when
    using the custom parameter.
    No default <?php wp_get_archives(before=<strong>); ?>
    Inserts the <strong> HTML tag
    before each link in the archive link list.
    after
    (string)
    Inserts text or formatting after the link in the archive list when
    using the custom parameter.
    No default <?php wp_get_archives(after=</strong>); ?>
    Inserts the </strong> HTML
    tag after each link in the archive link list.
    show_post_count
    (Boolean)
    This value displays the number of posts in the archive. You would
    use this if you use the type of monthly.
    true or 1
    false
    or 0
    <? wp_get_archives(show_post_count=1); ?>
    Displays the number of posts in each archive after each archive
    link.

Here are a couple of examples of tags used to display blog-post archives.

This tag displays a linked list of monthly archives (for example, November 2014, December 2014, and so on).

<?php wp_get_archives('type=monthly'); ?>

This next tag displays a linked list of the 15 most recent blog posts:

<?php wp_get_archives('type=postbypost&limit=15'); ?>