Codex

Template Tags/get month link

Contents

Description

Returns the monthly archive URL to a specific year and month for use in PHP. It does NOT display the URL. If year and month parameters are set to '', the tag returns the URL for the current month's archive.

Usage

 <?php get_month_link('year''month'); ?> 

Examples

Month Archive as Link

Returns the URL to the current month's archive as a link by displaying it within an anchor tag with the PHP echo command.

<a href="<?php echo get_month_link('', ''); ?>">All posts this month</a>

Assigning Specific Month to Variable

Returns URL to the archive for October 2004, assigning it to the variable $oct_04. The variable can then be used elsewhere in a page.

<?php $oct_04 = get_month_link('2004', '10'); ?>

Use With PHP Variables

PHP code block for use within The Loop: Assigns year and month of a post to the variables $arc_year and $arc_month. These are used with the get_month_link() tag, which returns the URL as a link to the monthly archive for that post, displaying it within an anchor tag with the PHP echo command. See Formatting Date and Time for info on format strings used in get_the_time() tag.

<?php
$arc_year = get_the_time('Y');
$arc_month = get_the_time('m');
?>
<a href="<?php echo get_month_link("$arc_year", "$arc_month"); ?>">archive
for <?php the_time('F Y') ?></a>

Parameters

year 
(integer) The year for the archive. Use '' to assign current year.
month 
(integer) The month for archive. Use '' to assign current month.

Related

edit_post_link, edit_comment_link, link_pages, wp_link_pages, get_year_link, get_month_link, get_day_link

How to pass parameters to tags with PHP function-style parameters

Go to Template Tag index