[Resolved] Showing time as well as date?

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Showing time as well as date?

This topic contains 12 replies, has 3 voices, and was last updated by  Sonja 1 week, 5 days ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #7298

    Matthew
    Participant

    Hi

    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! πŸ™‚

    #7307

    Tom
    Keymaster

    Hi there,

    Definitely possible with a filter. How would you like it to display?

    Let me know πŸ™‚

    #7308

    Matthew
    Participant

    Hey 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

    #7328

    Tom
    Keymaster

    Give 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 πŸ™‚

    #7349

    Matthew
    Participant

    That’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!

    #7380

    Tom
    Keymaster

    This 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

    #7428

    Matthew
    Participant

    Hey 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

    #7451

    Tom
    Keymaster

    I’m not sure I understand – can you show me your code and what it ends up looking like on the page?

    #7482

    Matthew
    Participant

    Hey

    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!

    #7491

    Tom
    Keymaster

    If 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 πŸ™‚

    #7629

    Matthew
    Participant

    It is yeah thanks Tom! πŸ™‚

    #7654

    Tom
    Keymaster

    You’re welcome πŸ™‚

    #7658

    Sonja
    Participant

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

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.