WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using CSS with the_date() (14 posts)

  1. bobdeo
    Member
    Posted 8 years ago #

    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

  2. yosemite
    Member
    Posted 8 years ago #

  3. bobdeo
    Member
    Posted 8 years ago #

    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...

  4. yosemite
    Member
    Posted 8 years ago #

    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.

  5. bobdeo
    Member
    Posted 8 years ago #

    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).

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

  7. yosemite
    Member
    Posted 8 years ago #

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

  8. bronto
    Member
    Posted 8 years ago #

    What about

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

  9. 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).

  10. bobdeo
    Member
    Posted 8 years ago #

    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 ;)

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

    the_date('<\sp\a\n \c\l...

  12. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    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\>');

  13. bobdeo
    Member
    Posted 8 years ago #

    G-R-E-A-T !

    Thanks !

  14. You don't technically need to escape every single character there, especially the < and >, but oh well. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags