Archived topic
How to display total comments below post title
9 replies · Started by WP on July 21, 2020
Hi,
I would like to display total comments below post title(h1) and before post description(paragraph). I looked around options but could not find such option. Also, I've added CrowdSignal thumbs up/down widget which is not aligned properly. I'm trying to have it displayed right below post title and once displaying total comments is possible, I could like to have thumbs up/down displayed before comments similar to below.
https://crowdsignal.com/features/
Hi there,
Can you:
- Disable the caching plugin first.
- Do you only want the comment link to display in single posts but not archives?
- As for CrowdSignal thumbs up/down widget, that's something you will need to check with their support as the CSS is all from the plugin from what I can see.
Leo,
This site is hosted in WordPress.com. I don't see caching plugin being activated.
Af for comments display link - I only want the link to display in single post (including total comments).
Let me check with CrowdSignal on resolving thumbs up/down widget position issue.
Ok this takes a couple of steps but try:
- Activate comment count for Archives in the customizer:
https://docs.generatepress.com/article/blog-content-layout/#archives
- Add this PHP snippet:
add_filter( 'generate_header_entry_meta_items', function( $items ) {
if ( is_single() ) {
$items = array(
'comments-link',
);
} return $items;
} );
Adding PHP: https://docs.generatepress.com/article/adding-php/
Then this CSS:
.single .comments-link {
display: block;
}
footer.entry-meta .comments-link {
display: none;
}
Adding CSS: https://docs.generatepress.com/article/adding-css/
1. Activated comment count for archives
2. Added php code on child theme
3. added custom css
Checked the single post, but comment counts are not showing up anywhere (both comment link and counts).
https://pasteboard.co/JiJHgnj.png
https://pasteboard.co/JiJHxaO.png
Found why it was not displaying. Once I enabled 'Display Post Author' for Single on Blog Layout, comment link started showing up.
https://pasteboard.co/JiJRyTR.png
Two more question:
1. How can I move comments similar to below
2. Display #of post views stats similar to below
1. How are you adding the thumb up/down currently?
You would need to add it using the after_entry_header hook with a hook element in order to reposition them:
https://docs.generatepress.com/article/hooks-element-overview/
2. You'd need a post view counter plugin.
Leo,
Thumb up/down are being displayed using CrowdSignal plugin. I have ticket open with their support to see if after_entry_header hook could be utilized.
Regarding displaying comment link below title (in post meta), I wanted to replace 'Leave a Comment' with 'Add Comment' with below code, but it not replacing the text.
add_filter( 'generate_leave_comment','st_custom_leave_comment' );
function st_custom_leave_comment() {
return 'Add Commment';
}
add_filter( 'generate_header_entry_meta_items', function( $items ) {
if ( is_single() ) {
$items = array(
'comments-link',
);
} return $items;
} );
Ok - this worked. It seems that WordPress.com business plan uses custom comment form.
add_filter( 'gettext', function( $text, $original, $domain ) {
if ( 'Leave a comment' === $text && 'generatepress' === $domain ) {
return 'Add Commment';
}
return $text;
}, 10, 3 );
Glad you've figured out and thanks for sharing!