Support » Fixing WordPress » Conditional is_date() Usage Question

  • Resolved 11Mystics


    I want to apply a class to a navigation list item when the page shown is a month archive, but not just any month, only the current month. Here’s my code:

    First I assemble a link to the current month archive:

    	$current_month = mysql2date('m', current_time('mysql'));
    	$current_year = mysql2date('Y', current_time('mysql'));
    	$issue = get_bloginfo('home') . "/" . $current_year . "/" . $current_month . "/";

    Next I use those variable on my list item…

    <li class="page <?php if (is_month()) { echo "current_page"; } ?>">
    	<a href="<? echo $issue; ?>">Read The Current Issue</a>

    My problem is, I need to have the conditional tag is_month() test whether it’s the current month, not just any month. The reason why is because if you hit any other month archive, it’s setting my navigation list item to the current page even when it’s not the “current month” :-/

    Hope that makes sense.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Returns the month and year of the current query

    if (is_month()) {
    $month = get_query_var('monthnum');
    $year = get_query_var('year');
    echo 'query is ' . $month .'/'.$year;

    I’m beginning to like you A LOT! Thanks for another life-saver solution 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditional is_date() Usage Question’ is closed to new replies.