Viewing 21 posts - 1 through 21 (of 21 total)
  • Author
    Posts
  • #1466513

    Hi there

    I’m running several Masonry grids on my site https://stegemueller.dk and I’m really happy with them.

    My readers are asking for the option to show the number of comments per post, so they don’t have to open the post to see if there are comments or if I have answered their comment.

    Can you help with this?

    Sincerely
    Hanne B. Stegemüller
    Denmark, Denmark

    #1466586

    Hey Stegemueller,

    Thank you for the inquiry.

    Please add this filter in the functions.php file to append the comment number beside the masonry title:

    function append_comments_to_masonry_title( $the_title, $entry, $atts ) {
        $comments_number = get_comments_number( $entry->ID );
        if ( $comments_number > 0 ) {
            $the_title .= ' <span class="av-masonry-comment-count">(' . $comments_number . ' comments)</span>';
        }
        return $the_title;
    }
    add_filter( 'avf_masonry_entry_title', 'append_comments_to_masonry_title', 10, 3 );
    
    

    You can then use the av-masonry-comment-count class name to adjust the style of the comment count.

    Best regards,
    Ismael

    #1466599

    Hi Ishmael

    Thank you very much for the code you sent me, which I have passed on to my developer, as I don’t dare mess with code myself – I’m not skilled enough!

    When we’re done, I’ll get back to you so you can see how nice it turned out.

    Sincerely yours
    Hanne B. Stegemüller
    Denmark, Denmark

    #1466611

    Hello again Ismael

    This is a strange comment – I do it a good as I can (and I have a painter in my flat so all ic chaos :-)

    My developer says that the filter is added to functions.php, but he can not make it work.

    All cache is of course cleared. I am not on Clouflare anymore.

    We are talking about the 3 grids on the frontpage on https:///stegemueller.dk

    I send you the credentialls in the “private content”-section.

    What else can I do for you?

    Best regards

    #1466697

    Hi,

    Thank you for the update.

    The Appearance > Theme File Editor was not accessible when we checked the dashboard, so we couldn’t test the modification. Please ask your developer to enable it or provide the FTP details in the private field.

    Best regards,
    Ismael

    #1466731
    This reply has been marked as private.
    #1466771

    Hi,

    Thank you for the info.

    Could you point us to the actual site folder or directory on the server? There are many folders and other websites on the server, and we are not sure which one to check.

    Best regards,
    Ismael

    #1466791

    but isn’t it an existing feature inside postslider.php to show the comments count?
    Enfold – Blog Layout – Blog Meta Elements

    #1466792

    Hi Ismael

    My developer says you are asking for the ”public_html”-folder.
    I can tell you that there is also a subdomain where you can test if you need to test. The subdomain is simply called subdomain.stegemueller.dk.
    Credentials are tha same as I’ve already sent you as it is a clone.

    #1466865

    Hi,

    Thank you for the info.

    We edited the functions.php file and adjusted the filter a bit. The comments number is now displaying beside the title. You can add a bit of css to adjust the style of the counter.

    function avf_append_comments_to_masonry_title( $the_title, $entry, $atts ) {
    	$comments_number = get_comments_number( $entry['ID'] );
    
    	if ( $comments_number > 0 ) {
    		$the_title .= ' <span class="av-masonry-comment-count">(' . $comments_number . ' comments)</span>';
    	}
    	return $the_title;
    }
    add_filter( 'avf_masonry_entry_title', 'avf_append_comments_to_masonry_title', 10, 3 );

    Best regards,
    Ismael

    #1466871

    hey – ismael – can you test if this will work too:
    this is a little bit different – as you can see – and with the included translation and differs between singular and plural case

    function avf_append_comments_to_masonry_title( $the_title, $entry, $atts ) {
    	$commentCount = get_comments_number( $entry['ID'] );
    	$text_add = $commentCount === '1' ? __( 'Comment', 'avia_framework' ) : __( 'Comments', 'avia_framework' );
    	if ( $commentCount > 0 ) {
    		$the_title .= " <span class='av-masonry-comment-count'> ({$commentCount} {$text_add}) </span>";
    	}
    	return $the_title;
    }
    add_filter( 'avf_masonry_entry_title', 'avf_append_comments_to_masonry_title', 10, 3 );
    #1466872

    Waugh both Ismael and Guenni

    This looks very interesting. Thank you so much.

    I really lik what Guenni is proposing with differ between singular and plural case. When I see pages where they don’t differentiate between singular and plural, I think it looks so sloppy!

    Of course we will translate ‘Comments’ to ‘Kommentarer’ and ‘Comment’ to ‘Kommentar’, so it is correct in Danish.

    All the best
    Hanne,
    Denmark

    #1466873

    this is already done by the language files (for your language too, I hope), in German this is the case.
    see here a blog example page ( the green Titles) : https://webers-testseite.de/masonry-blog/

    and a bit of css:

    .av-masonry-entry-title .av-masonry-comment-count {
      font-size: 0.8rem;
      color: #666
    }
    #1466874

    In Denmark we speak and write Danish :-)

    And they are not translated as what I see now is e.g.”8 comments”

    Thank you for the CSS code.

    #1466875

    To Guenni: Waugh I really like the image with the two cyclists (where you added a test comment).

    #1466878

    do you use my snippet? – if you are using da_DK lang file

    wow – no changes in your translations since version 3.6 ?

    #1466879

    Unfortunately, at the moment I’m not using anything as my home is full of tradesmen and I only have access to a small laptop. That’s why my developer is involved.

    #1466882

    Many thanks to both Guenni and Ismael.

    It’s turned out just as I wanted and now I’m sure my many readers and commenters will be happy.

    #1466919

    Hi,

    Thanks for the update. Please let us know if you should need any further help on the topic, or if we can close it.

    Best regards,
    Rikard

    #1466920

    Hi Rikard

    You can close this topic.
    Have a great weekend.

    Hanne,
    Denmark.

    #1466956

    Hi,

    Thanks for letting us know. Please open a new thread if you should have any further questions or problems.

    We wish you a good weekend too :-)

    Best regards,
    Rikard

Viewing 21 posts - 1 through 21 (of 21 total)
  • The topic ‘Show number of comments per post in Masonry’ is closed to new replies.