Put Comments-Link into entry-meta
-
Hi @donnerhall,
Have you already set up a child theme for Libretto? If so, the first step is to copy/paste the libretto_posted_on() function from the parent theme’s inc/template-tags.php file to your child theme’s functions.php file:
function libretto_posted_on() { $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%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() ) ); $posted_on = sprintf( esc_html_x( 'Posted on %s', 'post date', 'libretto' ), '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>' ); // Since this is being called outside the Loop on single post pages, we need // to use a workaround in order to access author info if ( is_singular() ) : $author_id = get_queried_object()->post_author; $author_url = get_author_posts_url( $author_id ); $author_name = get_the_author_meta( 'display_name', $author_id ); // Anywhere else we're inside the Loop, and we can do stuff like normal else : $author_url = get_author_posts_url( get_the_author_meta( 'ID' ) ); $author_name = get_the_author(); endif; $byline = sprintf( esc_html_x( 'by %s', 'post author', 'libretto' ), '<span class="author vcard"><a class="url fn n" href="' . esc_url( $author_url ) . '">' . esc_html( $author_name ) . '</a></span>' ); echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK. }
The following line defines the information that’s outputted onto your browser:
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
You can add this code beneath that to include a link to your comments section and also the number of comments on that post:
echo '<span class="comments-link">'; comments_popup_link( esc_html__( 'Leave a comment', 'libretto' ), esc_html__( '1 Comment', 'libretto' ), esc_html__( '% Comments', 'libretto' ) ); echo '</span>'
;
If you wish to completely remove the author name then remove the following portion of the code:
<span class="byline"> ' . $byline . '</span>'
Let me know how you get on with that! I’ll be happy to help with extra questions too.
- The topic ‘Put Comments-Link into entry-meta’ is closed to new replies.
(@donnerhall)
7 years, 7 months ago
Hey there,
I’m trying to put the Comments-link, or better, the number of comments, into the entry-meta – instead of the author. I’m pretty sure, I just need to adjust this
to make the link show, but so far I just end up breaking the template. Any ideas?