WordPress.org

Ready to get started?Download WordPress

Forums

Styling entry_date (5 posts)

  1. Helen-kh
    Member
    Posted 3 years ago #

    Hi,

    I want to style the date of the post in a box like below with a background color:
    Dec
    31
    2011

    I have read many forums that say use some php lines like:

    <div class="date-month"><?php the_time('M'); ?></div>
            <div class="date-day"><?php the_time('d'); ?></div>
            <div class="date-year"><?php the_time('Y'); ?></div>

    But I am not sure where I should put this piece of code. In loop.php or function.php? and do I have to substitute any other piece of code?
    I am using twentey-ten theme and I found this code in function.php that last line seems to be responsible for outputting the date:

    [please use the code button to mark your code and to keep from getting distorted - see http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

    function twentyten_posted_on() {
    	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		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()
    		),

    Does anybody know what to do for this please?

  2. how do you want the rest of the 'posted on' line to look like?

    the code changes will depend on the total layout of that line.

  3. Helen-kh
    Member
    Posted 3 years ago #

    I am deleting or use display:none for the rest of the line. I only want to keep the date for now.
    well, I found this code to add to the get_the_date, and style each part somehow.

    get_the_date('<\s\p\a\n \c\l\a\s\s="\m\o\n\t\h">M</\s\p\a\n><\b\r /><\s\p\a\n \c\l\a\s\s="\d\a\t\e">j</\s\p\a\n><\b\r /><\s\p\a\n \c\l\a\s\s="\y\e\a\r">Y</\s\p\a\n>')
    ),
    It seems a bit messy but it works. Is there a better and professional way to do this?
    I am also open to codes which keep the rest of posted on line, cause you never know if you change your mind again.

    Thanks a lot!

  4. this would also work:

    function twentyten_posted_on() {
    	printf( __( '<span class="%1$s">Posted </span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s%4$s%5$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			'<span class="date-month">'.get_the_date('M').'</span>',
            	'<span class="date-day">'.get_the_date('d').'</span>',
            	'<span class="date-year">'.get_the_date('Y').'</span>'
    			),

    and this would 'hide' the 'Posted by author':
    .meta-prep, .entry-meta .author, .entry-meta .meta-sep { display:none; }

  5. Helen-kh
    Member
    Posted 3 years ago #

    Thank you so much :)

Topic Closed

This topic has been closed to new replies.

About this Topic