How to display number of comments when comments are closed

Community Forums Forums Design Tips and Tricks How to display number of comments when comments are closed

This topic is: not resolved

Tagged: 

This topic contains 6 replies, has 4 voices, and was last updated by  outsidethebox 11 months, 2 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #68130

    justcurious
    Member
    Post count: 4

    I am trying to display both the number of comments (in post meta) and, if applicable, a notice that comments are closed (and I do have cases where comments are closed, but there are 1 or more comments). I am using the following function, which works fine when comments are open, but when comments are closed, all comment info disappears — I only see the author & post date. Sorry I cannot provide a link, but am working on a local install.

    add_filter( 'genesis_post_info', 'my_post_info_filter' );
    function my_post_info_filter( $post_info ) {
    if ( ! comments_open() ) {
    $post_info = 'Posted by [post_author_posts_link] on [post_date] [post_comments zero="Comments are closed." one="1 Comment Comments closed" more="% Comments Comments closed"] [post_edit]';}
    else {
    $post_info = 'Posted by [post_author_posts_link] on [post_date] [post_comments zero="Leave a Comment" one="1 Comment" more="% Comments"] [post_edit]';}
      return $post_info;
    
    }

    Thanks!

    #68543

    nutsandbolts
    Keymaster
    Post count: 3202

    You might try the Genesis Simple Comments plugin – I haven’t used it, so I’m not 100% sure it will help, but I know it lets you customize the text that shows up when comments are closed: http://designsbynickthegeek.com/plugins/genesis-simple-comments


    Andrea Whitmer, Owner, Nuts and Bolts Media
    I provide dev and training services for web designers • Find me on Twitter and Google+

    #68620

    Summer
    Participant
    Post count: 1123

    I was able to get this effect on one website by disabling comments in Settings > Discussions, but turning on comments in Genesis > Settings. No filters or plugins needed, after much trial and error.

    The site was an archive site, where we didn’t need new comments on any of the posts, but many of the existing posts had a few dozen comments each, and we wanted those to be displayed, at least in the single post view. The site is running Minimum v1, and Genesis 2.0.1, so it’s still working as intended.


    #68674

    justcurious
    Member
    Post count: 4

    Thank you both! I am a little worried about the plugin because it has not been updated in so long, and Summer, I can’t disable comments in settings — I do want new comments on most posts, but need to close them on some posts.

    I have finally figured out how to do this for the Comment title at the bottom of single posts, so will eventually manage to get it working in the post meta.

    #83099

    outsidethebox
    Member
    Post count: 10

    @justcurious
    Care to share the solution? Because I’m just curious about the same thing too :)

    THanks!

    #83118

    justcurious
    Member
    Post count: 4

    Outsidethebox, I never totally solved it for the post entry meta…I show when comments are closed, but if comments are closed and there are already existing comments, the number of comments only appears below the post. Here is what I’m using for post entry meta:

    add_filter( 'genesis_post_info', 'my_post_info_filter' );
    function my_post_info_filter( $post_info ) {
    if ( ! comments_open() ) {
    $post_info = 'Posted by [post_author_posts_link] on [post_date] — Comments are closed [post_edit]';}
    else {
    $post_info = 'Posted by [post_author_posts_link] on [post_date] [post_comments zero="Leave a Comment" one="1 Comment" more="% Comments"] [post_edit]';}
      return $post_info;
    
    }
    

    And here is what I use to show the number of comments at the bottom of the post:

    add_action( 'genesis_before_comments', 'my_before_comments', 15);
    function my_before_comments() {
    if ( ! comments_open()) {   
     return __(comments_number( '<h3>Comments are closed</h3>', '<h3>1 Comment &mdash; Comments are closed</h3>', '<h3>% Comments &mdash; Comments are closed</h3>' ), 'genesis' );
    }
    else {
    return __(comments_number( '<h3>No Comments</h3>', '<h3>1 Comment</h3>', '<h3>% Comments</h3>' ), 'genesis' );
    }
    }
    

    Note that that is BEFORE genesis_title_comments, so you need to do something with that…either filter it out altogether, or what I did was filter genesis_title_comments to display a link to my comment policy.

    If you come up with a better solution, hope you’ll post it here!

    #83182

    outsidethebox
    Member
    Post count: 10

    @justcurious
    Thanks for responding! While I was waiting, I came pretty much to the same thing as you for the post info, but it’s not a complete solution…

    And I’ve figured out the bottom part as well, albeit a little differently :)

    I show the number of comments before they start. This looks logical for all posts.

    // Modify comments header text in comments
    add_filter( 'genesis_title_comments', 'comments_title');
    function comments_title() {
    return __(comments_number( '<h3>Start Discussion</h3> ', '<h3>Comments: 1</h3>', '<h3>Comments: %</h3>' ) , 'genesis' );
    }

    And then I show the notification after the last comment (where the comment form displays when comments are open). This explains the absence of the comment form.

    //* Notify of closed comments
    add_action( 'genesis_after_comments', 'comments_closed' );
    function comments_closed() {
    	if ( is_single() && !comments_open() ) {
    	?>
    	<div class="comments-closed">
    		<h4>Comments are closed</h4>
    	</div>
    	<?php
    	}
    }

    Perhaps you’ll find this useful.

    I’ll keep digging, but my php skills come from google :)) I think we’ll have to look past shortcodes, as they limit our options. I’m surprised this is not taken into account in the framework, pretty standard stuff.

    • This reply was modified 11 months, 2 weeks ago by  outsidethebox. Reason: typo
    • This reply was modified 11 months, 2 weeks ago by  outsidethebox. Reason: typo
Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.