WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Comments in Moderation - Front of blog? (5 posts)

  1. glidem
    Member
    Posted 7 years ago #

    Is there any way to show how many comments are in moderation for admin etc on the front page of the blog (sidebar) rather than having to go to the admin page?

    Maybe a plugin or simple code I need to add?

  2. MichaelH
    Member
    Posted 7 years ago #

    This from wp-admin/index.php

    $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
    echo $numcomments;
  3. glidem
    Member
    Posted 7 years ago #

    Great thanks...

    I am now using this code on my webpage:

    <?php
    $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
    echo '(',$numcomments,')';
    ?>

    Anyway to make only admin see it though?

  4. MichaelH
    Member
    Posted 7 years ago #

    An if statement similar to:

    if ( current_user_can('edit_users') )

  5. glidem
    Member
    Posted 7 years ago #

    Thanks it works great now, very useful!

    In case anyone else is wondering, this is the code I used in the sidebar of the theme:

    <?php if ( current_user_can('edit_users') ) { ?><?php
    $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
    echo '<small>(',$numcomments,')</small>';
    ?><?php } ?>

    I actually put this in a <h2> tag next to the title text, so I could see clearly at the top how many comments were in moderation very quickly.

Topic Closed

This topic has been closed to new replies.

About this Topic