“what I need it to do is change when the user clicks on an archived month.“
You can get as complicated as you want with this. And if you don’t know PHP it will get complicated. But just trust me…
The only part we need to change is the initial one I provided:
<?php $cur_month = strtolower(date('F')); ?>
This is going to expand bit so we can properly decide what to assign $cur_month. The following hits *current* on the home page, but the archive’s month on archived query pages:
<?php
global $month, $wp_query;
if( is_archive() ) {
$cur_month = strtolower($month[$wp_query->query['monthnum']]);
} else {
$cur_month = strtolower(date('F'));
}
?>
Let’s go over what’s happening here:
is_archive() is a WordPress conditional tag that returns true if we’re on an archive page (i.e. posts for November 2007). When we are, we can access the archive month through $wp_query->query['monthnum']
— however it’s only the numeric value, so we also have to pass it as an array key to the global variable $month (which hold the names of the months).
If we’re not on an archive page, the default is to use the current date (‘F’ is a format character that tells it to only return the full text name for the month), as before.
For both, strtolower() is a PHP function which just returns any string it’s passed in all lowercase characters.
Now, if you’d like this to work with the current month, the archive’s month, and the month for a post when on a post’s permalink page:
<?php
global $month, $wp_query;
if( is_archive() ) {
$cur_month = strtolower($month[$wp_query->query['monthnum']]);
} elseif( is_single() ) {
$cur_month = strtolower($month[substr($wp_query->post->post_date, 5, 2)]);
} else {
$cur_month = strtolower(date('F'));
}
?>
The first and last if blocks are the same. The one we perform for is_single() (single post page) does something similar to the archive month, but collects the numeric month from the $post object’s post_date property (substr() is another PHP function, this one letting us pick out the month from the post_date’s format of YYYY-MM-DD HH:MM:SS).