WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Showing Dates - Month Numbers to Month Strings (1 post)

  1. arondelle3
    Member
    Posted 7 years ago #

    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>
    <ul>
    <?php
    $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>
    </ul>
    <ul>
    <?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; ?>
    </ul>
    <?php endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic