WordPress.org

Ready to get started?Download WordPress

Forums

Hide recent comments if none exist (4 posts)

  1. kristinachilds
    Member
    Posted 1 year ago #

    Am I crazy or just blind? This seems like it would be a really simple thing to do without modifying the core files or installing a plug-in, yet I can't find a single thing on the interwebs that would help me figure out how to do this.

    Is there something I can put into functions.php?

  2. deepbevel
    Member
    Posted 1 year ago #

    I think if you just use this:

    <?php comments_popup_link(’0 Comments’, ’1 Comment’, ‘% Comments ‘); ?>

    and remove the message text "0 comments" ?

  3. kristinachilds
    Member
    Posted 1 year ago #

    that one i get. it's the recent comments widget in the sidebar i'm asking about. where you can choose how many of the comments to display with an excerpt of the comment that then goes to that post comment

  4. deepbevel
    Member
    Posted 1 year ago #

    if you can get the css for your recent comments widget you might be able to do something like this as a function, but I'm weak with code and this is not tested, but this is the general idea:

    function hide_if_no_comment() { 
    
    $comment_count = get_comment_count($post->ID); ?>
    
    if ($comment_count < 1) : ?>
    
    echo '<style type="text/css"> 
    
    (css for recent comments widget)
    
    endif;
    
    {display:none;}
        </style>';
    }
    add_action('hide_if_no_comment');

    I'm trying to say, "if comments are less than one, dont display the recent comments widget"

Topic Closed

This topic has been closed to new replies.

About this Topic