在评论中显示星级

时间:2019-01-08 13:36:07

标签: wordpress

我遵循了本文中的步骤:cssigniter.com/add-rating-wordpress-comment-system向评论系统添加星号...但是当我在星号下面没有显示代码的情况下列出评论时,我已经尝试过一百万件事,我似乎无法弄清楚为什么星星没有出现。

这是我用来发表评论的代码

    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; 
    } 

1 个答案:

答案 0 :(得分:0)

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;
    }