I want to add the number of comments beside the title. Just the number. Any help would be greatly appreciated. Thanks.
Add Comment Numbers Beside Title
(7 posts) (2 voices)-
Posted 6 months ago #
-
Hi Rickey,
Inside the functions.php of your Child Theme you need to add this code:
function title_comments($title){ if (comments_open()) { $postcommentnumber = get_comments_number(); if ($postcommentnumber > '1') { $postcomments = ' <span class="comments-link"><a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">'; $postcomments .= get_comments_number() . __(' Comments', 'thematic') . '</a></span>'; } elseif ($postcommentnumber == '1') { $postcomments = ' <span class="comments-link"><a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">'; $postcomments .= get_comments_number() . __(' Comment', 'thematic') . '</a></span>'; } elseif ($postcommentnumber == '0') { $postcomments = ' <span class="comments-link"><a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">'; $postcomments .= __('Leave a comment', 'thematic') . '</a></span>'; } } else { $postcomments = ' <span class="comments-link comments-closed-link">' . __('Comments closed', 'thematic') .'</span>'; } $title .= $postcomments; return $title; } add_filter('thematic_postheader_posttitle','title_comments');This puts the number of comments after the <h2>My post title</h2>. From here you can use css to style it accordingly and position it where you need it.
Posted 6 months ago # -
Is it possible to have it inside the H2 and with a link to the comments?
Posted 6 months ago # -
This is with a link to the comments. And if you want it inside the H2 try this code:
function title_comments($title){ if (comments_open()) { $postcommentnumber = get_comments_number(); if ($postcommentnumber > '1') { $postcomments = ' <span class="comments-link"><a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">'; $postcomments .= get_comments_number() . __(' Comments', 'thematic') . '</a></span>'; } elseif ($postcommentnumber == '1') { $postcomments = ' <span class="comments-link"><a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">'; $postcomments .= get_comments_number() . __(' Comment', 'thematic') . '</a></span>'; } elseif ($postcommentnumber == '0') { $postcomments = ' <span class="comments-link"><a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">'; $postcomments .= __('Leave a comment', 'thematic') . '</a></span>'; } } else { $postcomments = ' <span class="comments-link comments-closed-link">' . __('Comments closed', 'thematic') .'</span>'; } $postcomments = $postcomments . '</h2>'; $end_of_heading = '-</h2>-'; return preg_replace($end_of_heading, $postcomments, $title, 1); } add_filter('thematic_postheader_posttitle','title_comments');Posted 6 months ago # -
Okay, that worked, that you so much! I will tweak my CSS now.
Posted 6 months ago # -
Don't forget to post a link when it's done ;)
Posted 6 months ago # -
Here: http://www.rickey.org
Thanks for all your help!
Posted 5 months ago #
Reply
You must log in to post.