- This topic has 12 replies, 3 voices, and was last updated 2 years ago by
David.
-
AuthorPosts
-
April 15, 2020 at 12:32 am #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,
April 15, 2020 at 10:27 am #1240464Tom
Lead DeveloperLead DeveloperHi 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 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 15, 2020 at 7:08 pm #1240867Matthew
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,
April 16, 2020 at 8:55 am #1241777Tom
Lead DeveloperLead DeveloperAny chance you can link me to the post? I’m not able to get through the password protected page right now.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 16, 2020 at 7:34 pm #1242332Matthew
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-1242320The ‘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,
April 17, 2020 at 9:42 am #1243240Tom
Lead DeveloperLead DeveloperCan you try the updated code?: https://generatepress.com/forums/topic/post-meta-with-last-updated-date/#post-1240464
Let me know 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 20, 2020 at 1:43 am #1246209Matthew
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.
April 20, 2020 at 3:20 am #1246338David
StaffCustomer SupportHi 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>';
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 20, 2020 at 6:56 pm #1247357Matthew
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,
April 21, 2020 at 3:01 am #1247647David
StaffCustomer SupportCan 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 ); }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 21, 2020 at 9:56 pm #1248731Matthew
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
April 21, 2020 at 10:06 pm #1248733Matthew
Don’t worry about this for now, I’m going to try another approach, and re-post.
thanks,
April 22, 2020 at 3:02 am #1248963David
StaffCustomer SupportI updated the code here as i forgot to add in the labels.
Give that a go and let us know.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.