[Resolved] Adding Comment Count to Single Blog Post

Home Forums Support [Resolved] Adding Comment Count to Single Blog Post

Home Forums Support Adding Comment Count to Single Blog Post

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #1477399
    Donna

    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

    #1477412
    Tom
    Lead Developer
    Lead Developer

    Hi 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/

    #1477448
    Donna

    Hi 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

    #1477461
    Tom
    Lead Developer
    Lead Developer

    I’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/

    #1477469
    Donna

    Thanks 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

    #1477473
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #1657362
    Marius

    Hi 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?

    #1657438
    Leo
    Staff
    Customer Support

    Hi Marius,

    Can you open a new topic for your question?

    Thanks πŸ™‚

    #1657664
    Marius

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

    #1657712
    Marius

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

    #1658275
    Leo
    Staff
    Customer Support

    Sounds good.

    1.13.0 Alpha coming out this week which will make customizing the entry meta much much easier πŸ™‚

    #1659689
    acela

    Tom’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:

    Screengrab

    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!

    #1659698
    Elvin
    Staff
    Customer Support

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

    #1659734
    acela

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

    #1659745
    Elvin
    Staff
    Customer Support

    Nice catch! Glad you got it sorted. πŸ˜€

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