In archive.php, if it is a date archive, can I get the date using a function?
Consider a url like this: myfirstsite/2013/08 – I want to get the 2013/08
1 Answer
Use get_query_var()
to get the date parts:
$year = get_query_var('year');
$monthnum = get_query_var('monthnum');
$day = get_query_var('day');
In wp_title()
a call to get_query_var('m')
is used for the month too, but I got always just a 0
as value even on an URL like /2008/09/05/
.
If you want to print the month name, use:
$GLOBALS['wp_locale']->get_month($monthnum);
The month name will be translated by WordPress then.
There are also four conditional functions you can use:
is_year()
is_month()
is_day()
is_date()