在评论中显示星级 [英] Show star ratings in comments

查看:26
本文介绍了在评论中显示星级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本文中的步骤操作:cssigniter.com/add-rating-wordpress-comment-system 为评论系统添加星级...但是当我用下面的代码列出评论时,星星没有显示出来找出星星没有出现的原因.

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

推荐答案

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

这篇关于在评论中显示星级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆