I bet there’s an easier way, using WP API and internal variables, but I do not know enough about WP yet…
But actually, the PHP programming to display these info is not so heavy, depending on what you want…
whether you use mod_rewrite or not, all archive parameters are passed to the page in the $_REQUEST[]
variable.
The following bits of code should display respectively the day, month and year (if any) of the category being displayed:
<?php echo $_REQUEST['day']; ?>
<?php echo date("F", strtotime($_REQUEST['monthnum'])); ?>
<?php echo $_REQUEST['year']; ?>
However, the previous bits are of little use if you have a common template for month and year archives (since you won’t know when to display either date format).
This slightly more complex block would solve the problem:
<?php
$day_tmp = "D F G, Y";
$month_tmp = "F Y";
$year_tmp = "Y";
if (! empty($_REQUEST['day']))
echo date($day_tmp, strtotime( $_REQUEST['year'] . "-" . $_REQUEST['monthnum'] . "-" . $_REQUEST['day']) );
elseif (! empty($_REQUEST['monthnum']))
echo date($month_tmp, strtotime( $_REQUEST['year'] . "-" . $_REQUEST['monthnum'] . "-01") );
elseif (! empty($_REQUEST['year']))
echo date($year_tmp, strtotime( $_REQUEST['year'] . "-01-01") );
?>
With this one bit, you do not have to worry about any check… it will only display date info when they are available.
All you have to do is change the template format for each archive type (the $day_tmp
etc. at the beginning). They use PHP’s date()
syntax, which is pretty easy and completely documented here: https://www.php.net/date
Hope this help.