• In single.php I have a code:
    <?php printf(__(‘ was posted %1$s on %2$s at %3$s.

    %2$s supposedly prints the date of the post.

    Where can I control the format of the date?

    I have already set the date format for the website in Settings > General as “August 7, 2011” but on the post page the above code is rendered as:
    ” was posted on 06/08/2011 (Saturday) at 8:09 pm”

    Secondly, what could %1$s be printing, and when?

    Cheers!

    Raza

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    That is not the full printf so i assume it’s using get_the_date() and get_the_time();

    Formatting date and time: https://codex.www.ads-software.com/Formatting_Date_and_Time

    We have to see the full printf() to know what %1$s will be printing.

    Thread Starter razaj

    (@razaj)

    Thank you for your time.

    Here’s the full printf

    <?php printf(__(' was posted %1$s on %2$s at %3$s.<br><br>This entry is filed under: <br>%4$s.<br><br>', 'r755_light'), $time_since, get_the_time(__('d/m/Y (l)', 'r755_light')), get_the_time(), get_the_category_list(', ')); ?>

    What does it tell you?

    Moderator keesiemeijer

    (@keesiemeijer)

    The first variable is $time_since and I don’t know what it holds. Maybe something like (3 days ago). Try looking in the template file to see what it can hold.

    Formatting the date same as in Settings > General try this:

    <?php printf(__(' was posted %1$s on %2$s at %3$s.<br><br>This entry is filed under: <br>%4$s.<br><br>', 'r755_light'), $time_since, get_the_date(__('F j, Y', 'r755_light')), get_the_time(), get_the_category_list(', ')); ?>

    Thread Starter razaj

    (@razaj)

    Thank you keesiemeijer.

    You are a lifesaver!

    On a related note, where should I look for more info on $time_since ? Its not there in single.php.

    Moderator keesiemeijer

    (@keesiemeijer)

    I think it should be in the loop. If it’s not you can leave it out:

    <?php printf(__(' was posted on %1$s at %2$s.<br><br>This entry is filed under: <br>%3$s.<br><br>', 'r755_light'), get_the_date(__('F j, Y', 'r755_light')), get_the_time(), get_the_category_list(', ')); ?>

    Try looking in other template files but I think the setting of the variable should be set inside the loop.

    Thread Starter razaj

    (@razaj)

    Right.

    Aha. So its all sequential.

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘%2$s how to’ is closed to new replies.