-
AuthorPosts
-
September 9, 2024 at 11:19 am #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, DenmarkSeptember 10, 2024 at 4:47 am #1466586Hey 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,
IsmaelSeptember 10, 2024 at 6:14 am #1466599Hi 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, DenmarkSeptember 10, 2024 at 10:31 am #1466611Hello 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
September 11, 2024 at 12:08 pm #1466697Hi,
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,
IsmaelSeptember 11, 2024 at 5:11 pm #1466731This reply has been marked as private.September 12, 2024 at 4:32 am #1466771Hi,
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,
IsmaelSeptember 12, 2024 at 9:52 am #1466791but isn’t it an existing feature inside postslider.php to show the comments count?
Enfold – Blog Layout – Blog Meta ElementsSeptember 12, 2024 at 10:00 am #1466792Hi 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.September 13, 2024 at 4:28 am #1466865Hi,
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,
IsmaelSeptember 13, 2024 at 6:56 am #1466871hey – 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 casefunction 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 );
September 13, 2024 at 7:41 am #1466872Waugh 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,
DenmarkSeptember 13, 2024 at 7:48 am #1466873this 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 }
September 13, 2024 at 7:51 am #1466874In 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.
- This reply was modified 2 months, 1 week ago by Stegemueller.
September 13, 2024 at 7:55 am #1466875To Guenni: Waugh I really like the image with the two cyclists (where you added a test comment).
September 13, 2024 at 8:07 am #1466878do you use my snippet? – if you are using da_DK lang file
wow – no changes in your translations since version 3.6 ?
September 13, 2024 at 8:10 am #1466879Unfortunately, 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.
September 13, 2024 at 8:59 am #1466882Many 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.
September 13, 2024 at 7:37 pm #1466919Hi,
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,
RikardSeptember 13, 2024 at 7:38 pm #1466920Hi Rikard
You can close this topic.
Have a great weekend.Hanne,
Denmark.September 14, 2024 at 10:05 am #1466956Hi,
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 -
AuthorPosts
- The topic ‘Show number of comments per post in Masonry’ is closed to new replies.