Support » Themes and Templates » Using CSS with the_date()

  • Resolved bobdeo

    (@bobdeo)


    Hi,

    I want to separate the result of the_date() to apply different styles to day, month and year…

    Do you know how can I do that ?

    Thanks in advance

Viewing 13 replies - 1 through 13 (of 13 total)
  • ok thanks… but when I write

    <span class="day"><?php the_date('j') ?></span>
    <span class="month"><?php the_date('F') ?></span>
    <span class="year"><?php the_date('Y') ?></span>

    Only the first one is on the screen…

    From that page:
    When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() with a date-specific format string.

    The date for the first post -> that’s what I want. But I need to split day, month and year to apply a style to each (not the same for the 3).

    Well then you’ll need to use the_time() or something because as it says, the_date() only works once.

    e.g.;
    the_time('M');
    the_time('Y');
    the_time('j');

    What about

    the_date('<span class="day">j</span> <span class="month">F</span> <span class="year">Y</span>')

    Yeah, I was gonna suggest that, but I was too lazy to type it out as you need to escape a lotta characters in there with backslashes (all the ones that are real format characters).

    the_date('<span class="day">j</span> <span class="month">F</span> <span class="year">Y</span>')

    that’s sound good but not working… someone can correct it, I’m a newbie in php 😉

    As I said, you need to escape all the letters there are codes for stuff.

    the_date(‘<\sp\a\n \c\l…

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    the_date(‘\<\s\p\a\n \c\l\a\s\s\=\”\d\a\y\”\>j\<\/\s\p\a\n\> \<\s\p\a\n \c\l\a\s\s\=\”\m\o\n\t\h\”\>F\<\/\s\p\a\n\> \<\s\p\a\n \c\l\a\s\s\=\”\y\e\a\r\”\>Y\<\/\s\p\a\n\>’);

    G-R-E-A-T !

    Thanks !

    You don’t technically need to escape every single character there, especially the < and >, but oh well. 🙂

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Using CSS with the_date()’ is closed to new replies.