WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditional is_date() Usage Question (3 posts)

  1. 11Mystics
    Member
    Posted 5 years ago #

    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:

    <?php
    	$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>
    </li>

    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.

  2. MichaelH
    Member
    Posted 5 years ago #

    Returns the month and year of the current query

    <?php
    if (is_month()) {
    $month = get_query_var('monthnum');
    $year = get_query_var('year');
    echo 'query is ' . $month .'/'.$year;
    }
    ?>
  3. 11Mystics
    Member
    Posted 5 years ago #

    I'm beginning to like you A LOT! Thanks for another life-saver solution :)

Topic Closed

This topic has been closed to new replies.

About this Topic