Thread: Date format?

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Date format?


    Hi All-
    I'm trying to format some php in wordpress and not having any luck...

    I installed some code that added a css-styled date box containing post meta to each post on this wordpress site:

    http://OmniHotels.com/blog

    You'll see that each box has the month and day styled into it like this, and the day is styled into one colored box, and the month into another beneath it:
    14
    Nov

    but I want to instead style the date all into ONE colored box, in this format:
    Nov 14,
    2012

    Here is the php code as it currently stands:

    Code:
    /**
     * Customize Post Date format and add extra markup for CSS targeting.
     *
     * @author Gary Jones
     * @link   http://code.garyjones.co.uk/style-post-info/
     *
     * @param string $output Current HTML markup.
     * @param array  $atts   Attributes.
     *
     * @return string HTML markup.
     */
    function child_post_date_shortcode( $output, $atts ) {
    
    	return sprintf(
    		'<span class="date time published" title="%4$s">%1$s<span class="day">%2$s</span> <span class="month">%3$s</span></span>',
    		$atts['label'],
    		get_the_time( 'j' ),
    		get_the_time( 'M' ),
    		get_the_time( 'Y-m-d\TH:i:sO' )
    	);
    }
    And here is the CSS styling:

    Code:
    .post-info {
    	font-family: Arial, sans-serif;
    	font-size: 8px;
    	margin: 0 0 5px;
    	padding: 1px 0 5px 48px;
    }
    .post-info .time,
    .post-info .time span {
    	color: #fff;
    	display: block;
    	text-align: center;
    	width: 42px;
    }
    .post-info .time {
    	left: 10px;
    	position: absolute;
    	top: 10px;
    }
    .post-info .day {
    	background: #cbb28c;
    	font-size: 20px;
    	height: 18px;
    	line-height: 1em;
    	padding-top: 2px;
    	padding-bottom: 2px;
    	margin-left:5px;
    }
    .post-info .month {
    	background: #e2cdad;
    	height: 10px;
    	line-height: 1.33333;
    	text-transform: uppercase;
    	padding-top: 2px;
    	padding-bottom: 2px;
    	margin-left:5px;
    }
    
    #content .post {
    	position: relative;
    }
    #content .post h1 {
    	margin-left: 48px;
    }
    #content .post h2 {
    	font-size: 18px;
    	margin: 10px 10px 0 48px;
    }
    .hentry {
        position: relative;
    }
    Thanks for any help you can give!!

    Jay
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,508
    Rep Power
    594
    This is really a CSS question not PHP. However, I think you want 'display: inline' rather than 'display: block'.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by gw1500se
    This is really a CSS question not PHP. However, I think you want 'display: inline' rather than 'display: block'.
    Thanks, but doesn't the Year need to be added in the PHP coding? Right now it's only pulling the month and day.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,508
    Rep Power
    594
    I'm not familiar with wordpress but I would guess you just need to add the formatting for the year in the sprintf and using something like get_the_time( 'Y' ) for the year.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by gw1500se
    I'm not familiar with wordpress but I would guess you just need to add the formatting for the year in the sprintf and using something like get_the_time( 'Y' ) for the year.
    yes, that's what I'm asking for. Can you possibly help me with the syntax, how it should be added into the code to accomplish what I am trying to do?

    Again, I am trying to format it this way:

    Nov 14,
    2012

    and here is the php code. Please can you show me how it needs to read with the year added and in the right formatting?

    Code:
    function child_post_date_shortcode( $output, $atts ) {
    
    	return sprintf(
    		'<span class="date time published" title="%4$s">%1$s<span class="day">%2$s</span> <span class="month">%3$s</span></span>',
    		$atts['label'],
    		get_the_time( 'j' ),
    		get_the_time( 'M' ),
    		get_the_time( 'Y-m-d\TH:i:sO' )
    	);
    }
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,508
    Rep Power
    594
    Probably something like this. You may need to tune it to suit your needs.
    PHP Code:
    function child_post_date_shortcode$output$atts ) {

        return 
    sprintf(
            
    '<span class="date time published" title="%4$s">%1$s<span class="day">%2$s</span> <span class="month">%3$s</span><br /><span class="year">%4$s</span></span>',
            
    $atts['label'],
            
    get_the_time'j' ),
            
    get_the_time'M' ),
                    
    get_the_time'Y' ),
            
    get_the_time'Y-m-d\TH:i:sO' )
        );

    Note the use of [ PHP ] tags rather than [ CODE ] tags.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by gw1500se
    Probably something like this. You may need to tune it to suit your needs.
    PHP Code:
    function child_post_date_shortcode$output$atts ) {

        return 
    sprintf(
            
    '<span class="date time published" title="%4$s">%1$s<span class="day">%2$s</span> <span class="month">%3$s</span><br /><span class="year">%4$s</span></span>',
            
    $atts['label'],
            
    get_the_time'j' ),
            
    get_the_time'M' ),
                    
    get_the_time'Y' ),
            
    get_the_time'Y-m-d\TH:i:sO' )
        );

    Note the use of [ PHP ] tags rather than [ CODE ] tags.
    Thanks so much for your help!

IMN logo majestic logo threadwatch logo seochat tools logo