- This topic has 16 replies, 7 voices, and was last updated 3 years, 2 months ago by David.
-
AuthorPosts
-
October 7, 2020 at 1:45 pm #1477399Donna
I’ve read a few answers here but can’t find exactly what I’m looking for. I’d like to add the comments count in the blog post meta on a single blog post. Right after the date and name. What is the proper code that I need to add this and do I add it in the functions.php file in the child theme or somewhere else?
Many thanks in advance!
Donna
October 7, 2020 at 2:03 pm #1477412TomLead DeveloperLead DeveloperHi there,
This should do it:
add_filter( 'generate_header_entry_meta_items', function( $items ) { $items[] = 'comments-link'; return $items; } ); add_filter( 'generate_footer_entry_meta_items', function( $items ) { return array_diff( $items, array( 'comments-link' ) ); } ); add_action( 'wp', function() { if ( is_single() ) { add_filter( 'generate_show_comments', '__return_true' ); } } );
This can be added using one of these methods: https://docs.generatepress.com/article/adding-php/
October 7, 2020 at 2:28 pm #1477448DonnaHi Tom
Thanks so much for the speedy reply! That didn’t work for me, unfortunately. I tried it usign the Code Snippet plugin as well as adding to the functions.php file in the child theme.
Here’s the site:
https://www.analisamendmentblog.com/the-best-of-new-england/
Thanks for any guidance!
Donna
October 7, 2020 at 2:40 pm #1477461TomLead DeveloperLead DeveloperI’m seeing it right here: https://www.screencast.com/t/M1tM9f15xNjB
You can add a separator with some CSS:
header.entry-header .comments-link:before { content: " | "; display: inline-block; width: auto; margin: 0 5px 0 0; font-family: inherit; }
Adding CSS: https://docs.generatepress.com/article/adding-css/
October 7, 2020 at 2:49 pm #1477469DonnaThanks so much! Maybe I had a caching issue because I also see it now! And thanks for the CSS for the divider. Works perfectly!
Many thanks!!!
Donna
October 7, 2020 at 2:52 pm #1477473TomLead DeveloperLead DeveloperYou’re welcome π
February 13, 2021 at 3:57 pm #1657362MariusHi Tom,
I’ve been looking for a way to add comments count/link under the title with GeneratePress and the solution you presented works ONLY if one of the “Display post date” or “Display post author” is enabled in Layout > Blog > Single. If not, then the comments count is not shown.Any idea about how to show the comments count/link when post date and author are disabled on single page?
February 13, 2021 at 7:58 pm #1657438LeoStaffCustomer SupportHi Marius,
Can you open a new topic for your question?
Thanks π
February 14, 2021 at 4:31 am #1657664MariusIt is the same topic. Showing comment counts under the title.
I only stated that the solution provided by Tom is not working if you disable the showing of post date and author.February 14, 2021 at 6:33 am #1657712MariusI ended enabling post date so the entry meta area is displayed then hiding the post date with css. This way the comments link is displayed under the title alone.
February 14, 2021 at 2:37 pm #1658275LeoStaffCustomer SupportSounds good.
1.13.0 Alpha coming out this week which will make customizing the entry meta much much easier π
February 15, 2021 at 5:37 pm #1659689acelaTom’s PHP and CSS code above worked for me, but I’ve got this odd alignment issue between the date and the comments-link on mobile:
I tried mucking with the display: and vertical-align: CSS selectors in the
.entry-meta
div and spans, but couldn’t get the two fields to line up on narrow screens & windows…The second issue is adding the comments-link seemed to “push down” my entry-content (or Featured Image) quite a bit… The margin whitespace looks much greater between the bottom of the entry-meta and the top of the content when the comments-link is present, versus having just the date alone.
Suggestions welcome β thank you!
February 15, 2021 at 5:57 pm #1659698ElvinStaffCustomer SupportHi acela,
Can you link us to the page in question so we could?
If you wish to keep it private, can you open a new topic about this? So you could use the private information text field. Let us know. π
February 15, 2021 at 6:28 pm #1659734acelaHi Elvin,
Thanks so much for your fast response. It turns out I had previously added some custom CSS for .entry-meta (margin-bottom:) and .posted-on (display:) related to displaying the date… It was done many months ago when I first started the effort to port over my site, after checking out Brian Jackson’s blog on how to display the Updated date.
I figured this out by completely clearing my Additional CSS and seeing if the problems still happened. Fortunately, they went away β so I knew it was something on my end. It’s helpful technique for tracking things down! Once I removed that other CSS, everything was fine.
Sorry for the false alarm and thanks again for your help.
February 15, 2021 at 6:42 pm #1659745ElvinStaffCustomer SupportNice catch! Glad you got it sorted. π
-
AuthorPosts
- You must be logged in to reply to this topic.