Support » Themes and Templates » Showing Dates – Month Numbers to Month Strings

  • Resolved arondelle3


    I’m a newbie to WordPress, although I do have some experience as a programmer. The average programming language has a function to convert, say, string constants into numbers and vice versa. I know WordPress has functions like that, but I’ve spent the better part of two days trying to track them down in the Codex.

    Specifically, I’m search for the function that will convert the numerical month portion of the post date into the month name.

    All I want to do is create an archive page organized by year, with the months listed below each year. I found a code snippet which selects the post_date year and echoes it to the list as a link. This works as advertised.

    Getting the months to list under their respective years has got my stumped. Actually, I can get a sub-list to show up under each year, but the sub-list is blank (except for the bullets, of course).

    In the Codex article regarding archive pages, there is an example of the list which I’m trying to recreate; however, there’s no code showing how this is accomplished.

    Can someone please give me a clue — or even a snippet…?

    <h2>Archives by Year</h2>
    $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");
    foreach($years as $year) : ?>
    <li><a> "><?php echo $year; ?></a></li>
    <?php $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date) FROM $wpdb->posts WHERE post_status = 'publish' "); foreach($months as $month) : ?>
    <li><a> "><?php echo single_month_title($months); ?></a></li>
    <?php endforeach; ?>
    <?php endforeach; ?>

  • The topic ‘Showing Dates – Month Numbers to Month Strings’ is closed to new replies.