Show star ratings in comments

2019-08-16 17:23发布

I followed the steps in this article: cssigniter.com/add-rating-wordpress-comment-system to add a star rating to the comments system... but when I list the comments with the code below the stars are not showing up I have tried what seems like a million things and I can not seem to figure out why the stars are not showing up.

Here is the code I am using to pull the comments

    if ( is_user_logged_in() ) { 

    $user_id = get_current_user_id(); $args = array( 'status' => 'approve', 'user_id' => $user_id ); 
    $comments = get_comments($args); 
    foreach($comments as $comment) : echo '<p>';    
    $post_id = $comment->comment_post_ID;
    $member_name = get_post( $comment->comment_post_ID );

    echo (  ' <div style="color: #00205a;"> ' . mysql2date(get_option('date_format'), $comment->comment_date) . ' - </div>' . '<a style="color:#a27747;" href="' . get_permalink( $comment->comment_post_ID ) . '">' . $member_name->post_title . '</a><br />' . '(stars go here)' . '<br />' . $comment->comment_content ). '<br /><br />';


    echo '</p>'; 
    endforeach; 
    } 

标签: wordpress
1条回答
We Are One
2楼-- · 2019-08-16 17:45
if ( is_user_logged_in() ) {


    $user_id = get_current_user_id(); $args = array( 'status' => 'approve', 'user_id' => $user_id );
    $comments = get_comments($args);
    foreach($comments as $comment) : echo '<p>';  
    $member_name = get_post( $comment->comment_post_ID );

if ( $rating = get_comment_meta( $comment->comment_ID, 'rating', true ) ) {
    $stars = '<p class="stars">';
    for ( $i = 1; $i <= $rating; $i++ ) {
        $stars .= '<span class="dashicons dashicons-star-filled"></span>';
    }
    $stars .= '</p>';
}  

    echo (  ' <div style="color: #00205a;"> ' . mysql2date(get_option('date_format'), $comment->comment_date) . ' - </div>' . '<a style="color:#a27747;" href="' . get_permalink( $comment->comment_post_ID ) . '">' . $member_name->post_title . '</a><br />'. $stars . '<br />' . $comment->comment_content ). '<br /><br />';


    echo '</p>';
    endforeach;
    }
查看更多
登录 后发表回答