Home › Forums › Pro Support › Showing time as well as date?
- This topic has 12 replies, 3 voices, and was last updated 4 years, 7 months ago by
Sonja.
-
AuthorPosts
-
January 21, 2019 at 5:04 am #7298
Matthew
ParticipantHi
Is there a way to show the time as well as the date?
It would be good if there was an option to set how the date/time format showed as well?
Cheers! π
January 21, 2019 at 6:13 pm #7307Tom
KeymasterHi there,
Definitely possible with a filter. How would you like it to display?
Let me know π
January 21, 2019 at 6:55 pm #7308Matthew
ParticipantHey Tom!
Great news π
I was thinking like the following:
β21 Jan 2019, 10.30pm β
As an example date in the format Iβd like to achieve.
Cheers
January 22, 2019 at 4:43 pm #7328Tom
KeymasterGive this a shot:
add_filter( 'wpsp_date_output', function( $output ) { $time_string = '<time class="wp-show-posts-entry-date published" datetime="%1$s" itemprop="datePublished">%2$s, %5$s</time>'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string .= '<time class="wp-show-posts-updated" datetime="%3$s" itemprop="dateModified">%4$s, %5$s</time>'; } $time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ), esc_attr( get_the_modified_date( 'c' ) ), esc_html( get_the_modified_date() ), get_the_date( 'g:i a' ) ); return sprintf( '<span class="wp-show-posts-posted-on wp-show-posts-meta"> <a href="%1$s" title="%2$s" rel="bookmark">%3$s</a> </span>', esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string ); } );
Let me know π
January 23, 2019 at 11:39 am #7349Matthew
ParticipantThatβs great thanks, the time is showing now. π
I couldnβt see a way in the code though to change the date format. Is this possible?
Ideally I wanted to shorten the month I know how to do this in PHP date format just not sure where to change this.
Cheers!
January 23, 2019 at 6:31 pm #7380Tom
KeymasterThis is the part you’re looking for:
get_the_date( 'g:i a' )
You can check out the options here: https://codex.wordpress.org/Formatting_Date_and_Time
January 26, 2019 at 5:31 am #7428Matthew
ParticipantHey Tom,
Yeah I did see this but seems to only be to alter the time? Whilst I can add in the date here it still prints the date before this variable.
How can I alter the date format either before or disable it so I can add it in here?
Cheers
January 27, 2019 at 6:53 pm #7451Tom
KeymasterI’m not sure I understand – can you show me your code and what it ends up looking like on the page?
January 29, 2019 at 9:22 am #7482Matthew
ParticipantHey
Yeah of course, the code I am using is as follows:
add_filter( 'wpsp_date_output', function( $output ) { $time_string = '<time class="wp-show-posts-entry-date published" datetime="%1$s" itemprop="datePublished">%2$s, %5$s</time>'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string .= '<time class="wp-show-posts-updated" datetime="%3$s" itemprop="dateModified">%4$s, %5$s</time>'; } $time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ), esc_attr( get_the_modified_date( 'c' ) ), esc_html( get_the_modified_date() ), get_the_date( 'g:ia' ) ); return sprintf( '<span class="wp-show-posts-posted-on wp-show-posts-meta"> <a href="%1$s" title="%2$s" rel="bookmark">%3$s</a> </span>', esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string ); } );
The code
get_the_date( 'g:i a' )
only seems to be for the time part.If you look here – https://www.ukairdates.com at the latest TV shows news at the top of the page it shows the date and time.
I want to customise how the date looks.
Thanks for any help you can provide!
January 29, 2019 at 5:28 pm #7491Tom
KeymasterIf you want to customize how the date part looks, you’d change these lines:
esc_html( get_the_date() ),
And:
esc_html( get_the_modified_date() ),
Is that what you’re after?
Let me know π
February 5, 2019 at 2:16 pm #7629Matthew
ParticipantIt is yeah thanks Tom! π
February 6, 2019 at 8:50 pm #7654Tom
KeymasterYou’re welcome π
February 7, 2019 at 5:45 am #7658Sonja
ParticipantMay i ask, how to make this “Latest TV Show News” on the mentioned site? I would like to have such a box with handpicked posts above the normal posts from marketer site.
-
AuthorPosts
- You must be logged in to reply to this topic.