WordPress.org

Ready to get started?Download WordPress

Forums

Localised time format (strftime) for posts (3 posts)

  1. chtito
    Member
    Posted 9 years ago #

    I'd like to be able to use the (localised) strftime formatting for the titles of the blogs. That would allow titles like: Monday, December 23rd.

    In fact i did it myself on my blog. The only thing to do is to modify the functions mysqltodate in "functions.php" and the_date in "template-functions-general.php" by adding a supplementary boolean argument, say "use_local".

    Once these functions are modified you just have to put something like the_date('%A %e %B %G','<h2>','</h2>', 1, 1); for the title of each post.

    Can this feature be added in wordpress?

    Thank you!

  2. Kafkaesqui

    Posted 9 years ago #

    chtito, ever thought of sticking your changes into a plugin?

  3. chtito
    Member
    Posted 9 years ago #

    Yes, you're right!! Here is the plugin (it's too simple to be made a general purpose plugin, imo). I didn't use the strftime function because the right locale is very difficult to get. It requires to have the date in the ISO format, like 2005-01-13. So here is the code:

    function frenchMonth($n)
    {

    $months = array("janvier", "février",
    "mars", "avril", "mai", "juin", "juillet", "août",
    "septembre", "octobre", "novembre","décembre");
    return $months[$n-1];
    }

    function frenchWeekday($d)
    {
    $days = array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi");
    return $days[$d];
    }

    function localTimeFilter($theDate)
    {
    if (empty($theDate))
    return $theDate;
    $date = explode("-",$theDate);
    $phptime = mktime(0,0,0,$date[1], $date[2], $date[0]);

    return "<h2>".frenchWeekday(date("w", $phptime))." ".date("j", $phptime)." ".frenchMonth(date("n", $phptime))." ".date("Y", $phptime)."</h2>";
    //return "<h2>".strftime("%A %e %B %G", $phptime)."</h2>";
    }

    add_filter("the_date", "localTimeFilter");

    enjoy!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.