WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Put classes around the posted on date? (4 posts)

  1. Brig01
    Member
    Posted 3 years ago #

    Hello

    I have a question I've been wondering over for a long time.

    In the default twentyten template the posted on date is displayed using this code:

    %2$s

    This is great because the client can then change the date format through the UI. But I would like to style the date and would need classes around each part of the date.

    Something like:

    <time class="month">April</time><time class="day">02</time><time class="year">2011</time>

    I can easily do this by hard coding the date format but I would like the client to still be able to change the format.

    Does someone know if this is possible?

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    In the default twentyten template the posted on date is displayed using this code:

    %2$s

    not as simple as this;

    you need to look at the full code:

    the %2$s is a 'spaceholder' in the printf function for all this:

    sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			get_the_date()
    		),

    in there again %3$s is only a spaceholder for:

    get_the_date()

    to add your css classes, you probably (untested) only need to edit this last line, into something like:

    '<time class="month">' . get_the_date('F') . '</time><time class="day">' . get_the_date('d') . '</time><time class="year">' get_the_date('Y') . '</time>'

    http://codex.wordpress.org/Formatting_Date_and_Time

  3. Brig01
    Member
    Posted 3 years ago #

    Awesome! Thank you alchymyth, works perfectly!

    I actually always wondered what that 'spaceholder' was. Now I know how it works :)

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    you are welcome:

    happy client = happy designer = happy forum ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags