[Resolved] Post meta with last updated date

Home Forums Support [Resolved] Post meta with last updated date

Home Forums Support Post meta with last updated date

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

    I use the code from below resource:

    https://generatepress.com/forums/topic/read-more-button-and-author-gravatar/#post-623023

    also shown below

    add_filter( 'generate_post_author', '__return_false' );
    add_filter( 'generate_show_comments', '__return_false' );
    add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
    function tu_fancy_byline( $date ) {
    	printf( ' <span class="byline">%1$s</span>',
    		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
    			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    			esc_html( get_the_author() ),
    			get_avatar( get_the_author_meta( 'ID' ) )
    		)
    	);
    
    	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    		echo '<span class="comments-link">';
    			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
    		echo '</span>';
    	}
    
    	echo $date;
    }

    looks like:

    https://drive.google.com/open?id=1diZVX-EMeYJPULfpUT1jJhvMF-F9THTG

    1 problem how can I make the date the last modified date as in below:

    https://drive.google.com/open?id=1k0Mc-0sLyIamXfJgpACtHK_cHFKENpLZ

    I don’t want the published date anywhere, just the updated date.

    I find below resource:

    https://generatepress.com/forums/topic/please-help-me/

    and adjust the earlier code to the code below by replacing echo $date;

    add_filter( 'generate_post_author', '__return_false' );
    add_filter( 'generate_show_comments', '__return_false' );
    add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
    function tu_fancy_byline( $date ) {
    	printf( ' <span class="byline">%1$s</span>',
    		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
    			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    			esc_html( get_the_author() ),
    			get_avatar( get_the_author_meta( 'ID' ) )
    		)
    	);
    
    	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    		echo '<span class="comments-link">';
    			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
    		echo '</span>';
    	}
    
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    	
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$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() )
    	);
    
    	return sprintf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
    		$time_string
    	);
    }

    But now the date disappears completely, as shown below:

    https://drive.google.com/open?id=1QZ-UoDGZLuWwbbgTBbKDjgdcZvUdY5Tt

    thanks,

    #1240464
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this instead:

    add_filter( 'generate_post_author', '__return_false' );
    add_filter( 'generate_show_comments', '__return_false' );
    add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
    function tu_fancy_byline( $date ) {
    	printf( ' <span class="byline">%1$s</span>',
    		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
    			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    			esc_html( get_the_author() ),
    			get_avatar( get_the_author_meta( 'ID' ) )
    		)
    	);
    
    	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    		echo '<span class="comments-link">';
    			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
    		echo '</span>';
    	}
    
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    	
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="updated-date" datetime="%3$s" itemprop="dateModified">%4$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() )
    	);
    
    	printf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
    		$time_string
    	);
    }

    Let me know 🙂

    #1240867
    Matthew

    Hi Tom,

    I added a new testing line of text to my post and updated the post (after inserting your suggested code) but the date is still missing like the final image I uploaded on google drive above.

    I added your code to my site-specific plug-in, i.e.

    /public_html/wp-content/plugins/imjexa-plugin

    thanks,

    #1241777
    Tom
    Lead Developer
    Lead Developer

    Any chance you can link me to the post? I’m not able to get through the password protected page right now.

    #1242332
    Matthew

    Hi Tom,

    I’m sending the login details and post via your account issue form.

    David is having the same problem logging in and asked me to use that form, see below:
    https://generatepress.com/forums/topic/unique-header-for-a-specific-part-of-site/page/2/#post-1242320

    The ‘Your website URL’ that only admins can see adds extra characters which makes it confusing for you to see the actual U/P.

    Pls check form submission for me.

    thanks,

    #1243240
    Tom
    Lead Developer
    Lead Developer
    #1246209
    Matthew

    Thanks Tom it works,

    How can I refine this so that for a newly published post it displays as:

    Matthew Jones | 2 comments | Published on April 20, 2020

    and for any updated post it is:

    Matthew Jones | 2 comments | Last updated on April 20, 2020

    Currently I have:

    Matthew Jones | 2 comments | April 20, 2020

    thanks,

    note: the comments part is only shown on the archive page which is OK, it’s not on the single posts page which is how I want it.

    #1246338
    David
    Staff
    Customer Support

    Hi there,

    for the Published and Last Updated dates – you will need to edit the two lines beginning with $time_string

    Published date should read like so:

    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time>';

    and this for the Updated:

    $time_string = '<time class="updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on %4$s</time>';

    #1247357
    Matthew

    I just published a new test post and on the single post it is displaying as:

    Matthew Jones | Last updated on April 21, 2020

    and on the archive:

    Matthew Jones | 2 comments | Last updated on April 21, 2020

    I put my login earlier, is it possible to test this on your end to check it’s OK first?

    thanks,

    #1247647
    David
    Staff
    Customer Support

    Can you try this instead:

    add_filter( 'generate_post_author', '__return_false' );
    add_filter( 'generate_show_comments', '__return_false' );
    add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
    function tu_fancy_byline( $date ) {
    	printf( ' <span class="byline">%1$s</span>',
    		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
    			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    			esc_html( get_the_author() ),
    			get_avatar( get_the_author_meta( 'ID' ) )
    		)
    	);
    
    	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    		echo '<span class="comments-link">';
    			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
    		echo '</span>';
    	}
    
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time>';
        
        $updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' ) + 86400;
    	
    	if ( $updated_time > $published_time ) {
    		$time_string = '<time class="updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on %4$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() )
    	);
    
    	printf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
    		$time_string
    	);
    }
    #1248731
    Matthew

    Na doesn’t work as expected, just comes back to:

    Matthew Jones | April 21, 2020

    and on the archive:

    Matthew Jones | 2 comments | April 21, 2020

    #1248733
    Matthew

    Don’t worry about this for now, I’m going to try another approach, and re-post.

    thanks,

    #1248963
    David
    Staff
    Customer Support

    I updated the code here as i forgot to add in the labels.

    Give that a go and let us know.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.