在评论中显示星级评分

问题描述 投票:0回答:1

我按照本文中的步骤操作: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; 
    } 
wordpress
1个回答
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;
    }
© www.soinside.com 2019 - 2024. All rights reserved.