Support » Plugin: SB Login » Page of unread posts/comments

  • Resolved halcyon1234

    (@halcyon1234)


    Great plugin. The feature I use the most is {x} New Comments. I’d like to turn that into a hyperlink which goes to a custom page, and that page lists all the posts with new comments (or maybe the comments).

    Can the plugin have an function call exposes however you’re calculating that number, and return the query (or query results). So I can do something like:

    page-newcomments.php

    $comments = sb_new_comments();
    if ($comments) {display comments}

    page-newposts.php

    $posts = sb_new_posts();
    if($posts->has_posts()) { THE LOOP }

    https://wordpress.org/plugins/sb-login/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Fida Al Hasan

    (@fida02)

    Hello,

    You can show all recent comments of your site with a function. Paste this function in your theme’s function.php

    function wcz_recent_comments($no_comments = 15, $comment_len = 80, $avatar_size = 20) {
    
    $comments_query = new WP_Comment_Query();
    $comments = $comments_query->query( array( 'number' => $no_comments ) );
    $comm = '';
    if ( $comments ) : foreach ( $comments as $comment ) :
    $comm .= '<li>' . get_avatar( $comment->comment_author_email, $avatar_size );
    $comm .= '<a href="' . get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID . '">';
    $comm .= get_comment_author( $comment->comment_ID ) . ':</a>  ';
    $comm .= '' . strip_tags( substr( apply_filters( 'get_comment_text', $comment->comment_content ), 0, $comment_len ) ) . '</li>';
    endforeach; else :
    $comm .= 'No comments.';
    endif;
    echo $comm;
    }

    Now paste this in your theme where you want to show recent comments

    <?php wcz_recent_comments(); ?>

    You also asked for recent posts. Your home page shows recent posts of your site and author.php shows recent posts of a author. So I Think there no needs to make another template for it.

    To hyper link comments number go to sb-login/template/logged-in.php
    and turn this code into a hyper link

    <li><strong><span style="color:#0176AB;"><?php _e('Total comments of yours:', 'sb-login'); ?></span></strong> <?php
    global $wpdb, $current_user;
    get_currentuserinfo();
    $userId = $current_user->ID;
    $where = 'WHERE comment_approved = 1 AND user_id = ' . $userId ;
    $comment_count = $wpdb->get_var("SELECT COUNT( * ) AS total
                                     FROM {$wpdb->comments}
                                     {$where}");
    echo '<strong>' . $comment_count . '</strong>';
    ?></li>

    You’re right about the recent posts– silly me, I keep getting posts mixed up with comments.

    Thanks for the code snippet for the recent comments. It’s what I’m doing now, but I was hoping that instead of “recent comments”, it was instead a list of unread comments. Basically, when your plugin shows “2 new comments”, I was hoping to use the same query you use to figure out that number, and then show those 2 comments only. But I think your plugin just counts the number of comments since a certain date– except for posts the user has already read this session– something like that.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Page of unread posts/comments’ is closed to new replies.