WordPress.org

Forums

Display the name of the Month on the monthly archi (5 posts)

  1. chiensavant
    Member
    Posted 11 years ago #

    Humm.. Good luck.
    I believe you could retrieve the URI with PHP and extract the Month or Year from it, then translate it in full english, but that requires quite a lot of programming...
    Actually maybe not that much. But I cannot help in this department.

  2. drdave
    Member
    Posted 11 years ago #

    I bet there's an easier way, using WP API and internal variables, but I do not know enough about WP yet...
    But actually, the PHP programming to display these info is not so heavy, depending on what you want...
    whether you use mod_rewrite or not, all archive parameters are passed to the page in the $_REQUEST[] variable.
    The following bits of code should display respectively the day, month and year (if any) of the category being displayed:
    <?php echo $_REQUEST['day']; ?>
    <?php echo date("F", strtotime($_REQUEST['monthnum'])); ?>
    <?php echo $_REQUEST['year']; ?>
    However, the previous bits are of little use if you have a common template for month and year archives (since you won't know when to display either date format).
    This slightly more complex block would solve the problem:
    <?php
    $day_tmp = "D F G, Y";
    $month_tmp = "F Y";
    $year_tmp = "Y";
    if (! empty($_REQUEST['day']))
    echo date($day_tmp, strtotime( $_REQUEST['year'] . "-" . $_REQUEST['monthnum'] . "-" . $_REQUEST['day']) );
    elseif (! empty($_REQUEST['monthnum']))
    echo date($month_tmp, strtotime( $_REQUEST['year'] . "-" . $_REQUEST['monthnum'] . "-01") );
    elseif (! empty($_REQUEST['year']))
    echo date($year_tmp, strtotime( $_REQUEST['year'] . "-01-01") );
    ?>

    With this one bit, you do not have to worry about any check... it will only display date info when they are available.
    All you have to do is change the template format for each archive type (the $day_tmp etc. at the beginning). They use PHP's date() syntax, which is pretty easy and completely documented here: http://www.php.net/date
    Hope this help.

  3. drdave
    Member
    Posted 11 years ago #

    Ooops, just realized one of the template string above is wrong, it should be:
    $day_tmp = "D F j, Y";

  4. drdave
    Member
    Posted 11 years ago #

    bstovold,
    Glad you found a solution (definitely more elegant than my php hack)...
    however, you said:

    Of course, I wouldn't need to do this if I wasn't using mod_rewrite, as the $m, $y and $p variables would be available.

    As I said, this is not completely true: you can easily access month, year and day through $_REQUEST['monthnum'], $_REQUEST['year'] and $_REQUEST['day']
    Actually, that's all the mod_rewrite does: turns your slash-separated strings into POST arguments...

  5. Ruby Sinreich
    Member
    Posted 11 years ago #

    Hey, I got bstovold's code to work for my purposes just using built in variables: $single, $cat, $m, $author. Any page that doesn't have one of those values is the front page (at least according to my formula).

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.