我无法找到问题,显示头骨的帖子有6条评论由买家给出,5星评级,该authur拥有的其他帖子是否收到相同的评级和明星? ,星星和评级只应出现在它所给出的帖子上。
这里是一个小代码,可以让这个明星起来。 这是显示那些框中的星星的代码行
if(!function_exists('PricerrTheme_my_account_reviews_area_function'))
{
function PricerrTheme_my_account_reviews_area_function()
{
global $current_user;
get_currentuserinfo();
$uid = $current_user->ID;
//-------------------------------------
global $wpdb,$wp_rewrite,$wp_query;
$third_page = $wp_query->query_vars['third_page'];
$third_page = $_GET['pg'];
if(empty($_GET['pg'])) $third_page = 'home';
?>
<div id="content" class="directly-frame account-cnt">
<!-- page content here -->
<div class="box_title3"><?php _e("My Ratings",'PricerrTheme'); ?></div>
<div class="my_box3"><div class="shopping_menu_dv">
<?php
$using_perm = PricerrTheme_using_permalinks();
if($using_perm) $rev_pg_lnk = get_permalink(get_option('PricerrTheme_my_account_reviews_page_id')). "/?";
else $rev_pg_lnk = get_bloginfo('siteurl'). "/?page_id=". get_option('PricerrTheme_my_account_reviews_page_id'). "&";
?>
<ul id="shopping_menu">
<li><a <?php echo ($third_page == "home" ? 'class="actiove"' : ""); ?> href="<?php echo $rev_pg_lnk; ?>"><?php _e("Ratings to Award","PricerrTheme"); ?></a></li>
<li><a <?php echo ($third_page == "waiting" ? 'class="actiove"' : ""); ?> href="<?php echo $rev_pg_lnk; ?>pg=waiting"><?php _e("Pending Ratings","PricerrTheme"); ?></a></li>
<li><a <?php echo ($third_page == "my_rev" ? 'class="actiove"' : ""); ?> href="<?php echo $rev_pg_lnk; ?>pg=my_rev"><?php _e("My Ratings","PricerrTheme"); ?></a></li>
</ul>
</div></div>
<?php
if($third_page == "home"):
?>
<div class="my_box3">
<div class="padd10">
<script>
jQuery(document).ready(function() {
jQuery('.dd-submit-rating').click(function() {
var id = jQuery(this).attr('rel');
var uprating = jQuery("#rating_me-" + id + " :selected").val();
var reason = jQuery("#reason-" + id).val();
if(reason.length < 10) { alert("<?php _e('Please input a longer description for your rating','PricerrTheme'); ?>"); return false; }
jQuery.ajax({
type: "POST",
url: "<?php echo get_bloginfo('siteurl'); ?>/",
data: "rate_me=1&ids="+id+"&uprating="+uprating+"&reason="+reason,
success: function(msg){
jQuery("#post-" + id).hide('slow');
}
});
return false;
});
//-------------------------
});
</script>
<?php
global $wpdb;
$query = "select distinct *, ratings.id ratid from ".$wpdb->prefix."job_ratings ratings, ".$wpdb->prefix."job_orders orders where
ratings.awarded='0' AND orders.id=ratings.orderid AND orders.uid='$uid'";
$r = $wpdb->get_results($query);
if(count($r) > 0)
{
foreach($r as $row)
{
$post = $row->pid;
$post = get_post($post);
$user = get_userdata($row->touser);
?>
<div class="post" id="post-<?php echo $row->ratid; ?>">
<div class="padd10_only">
<div class="image_holder3">
<a href="<?php the_permalink(); ?>"><img width="65" height="50"
src="<?php echo PricerrTheme_get_first_post_image($row->pid,65,50); ?>" /></a>
</div>
<div class="title_holder3" >
<h2><a href="<?php echo get_permalink($row->pid); ?>"><?php echo PricerrTheme_wrap_the_title($post->post_title,$row->pid); ?></a></h2>
<div class="c111">Rate:</div>
<div class="c111"><textarea id="reason-<?php echo $row->ratid; ?>" rows="2" cols="35"></textarea></div>
<div class="c111"> <select name="rating_me" id="rating_me-<?php echo $row->ratid; ?>">
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
</div>
<div class="c111 ck999">
<a href="#" rel="<?php echo $row->ratid; ?>" class="dd-submit-rating"><?php _e('Submit Rating Now','PricerrTheme') ?></a>
</div>
</div>
</div>
</div>
<?php
}
}
else
{
_e("There are no reviews to be awarded.","PricerrTheme");
}
?>
</div></div>
<?php elseif($third_page == "waiting"): ?>
<div class="my_box3">
<div class="padd10">
<?php
global $wpdb;
$query = "select distinct * from ".$wpdb->prefix."job_ratings ratings, ".$wpdb->prefix."job_orders orders,
".$wpdb->prefix."posts posts where posts.ID=orders.pid AND
ratings.awarded='0' AND orders.id=ratings.orderid AND posts.post_author='$uid'";
$r = $wpdb->get_results($query);
if(count($r) > 0)
{
foreach($r as $row)
{
$post = $row->pid;
$post = get_post($post);
$user = get_userdata($row->uid);
?>
<div class="post" id="post-<?php echo $row->ratid; ?>">
<div class="padd10_only">
<div class="image_holder3">
<a href="<?php the_permalink(); ?>"><img width="65" height="50"
src="<?php echo PricerrTheme_get_first_post_image($row->pid,65,50); ?>" /></a>
</div>
<div class="title_holder3" >
<h2><a href="<?php echo get_permalink($row->pid); ?>"><?php echo PricerrTheme_wrap_the_title($post->post_title,$row->pid); ?></a></h2>
<?php echo sprintf(__('Waiting from: %s','PricerrTheme'), $user->user_login ); ?>
</div>
</div>
</div>
<?php
}
}
else
{
_e("You have no pending reviews.","PricerrTheme");
}
?>
</div>
</div>
<?php elseif($third_page == "my_rev"): ?>
<div class="my_box3">
<div class="padd10">
<?php
global $wpdb;
$query = "select distinct *, ratings.id ratid from ".$wpdb->prefix."job_ratings ratings, ".$wpdb->prefix."job_orders orders,
".$wpdb->prefix."posts posts where posts.ID=orders.pid AND
ratings.awarded='1' AND orders.id=ratings.orderid AND posts.post_author='$uid'";
$r = $wpdb->get_results($query);
if(count($r) > 0)
{
foreach($r as $row)
{
$post = $row->pid;
$post = get_post($post);
$user = get_userdata($row->touser);
?>
<div class="post" id="post-<?php echo $row->ratid; ?>">
<div class="padd10_only">
<div class="image_holder3">
<a href="<?php the_permalink(); ?>"><img width="65" height="50"
src="<?php echo PricerrTheme_get_first_post_image($row->pid,65,50); ?>" /></a>
</div>
<div class="title_holder3" >
<h2><a href="<?php echo get_permalink($row->pid); ?>"><?php echo PricerrTheme_wrap_the_title($post->post_title, $row->pid); ?></a></h2>
<div class="c111"><b><?php _e("Rated","PricerrTheme"); ?>: </b></div>
<div class="c111"><?php
echo PricerrTheme_show_stars_our_of_number($row->grade);
?>
</div>
<div class="clear10" style="float:left"></div>
<div class="c111"><b><?php _e("Description","PricerrTheme"); ?>: </b></div>
<div class="c111"><?php echo stripslashes($row->reason); ?>
</div>
</div>
</div>
</div>
<?php
}
}
else
{
_e("You have no reviews.","PricerrTheme");
}
?>
</div></div>
<?php endif; ?>
<!-- page content here -->
</div>
<?php
PricerrTheme_get_users_links();
} }
答案 0 :(得分:1)
尝试使用作者和帖子ID(或者只是postId)来获取查询:因为帖子独立于他们的ID并且它们是唯一的但作者后期只与帖子相关但不是独立,因为作者(uid)可以有多个帖子,但帖子将有单个&amp;唯一的帖子ID
我假设帖子ID目前也在同一张表中。并以postId,author(uid)
为例示例
echo pricerrtheme_show_rating_star_user($post->post_author, $post_id);
同样修改函数和mysql查询
功能:
function pricerrtheme_show_rating_star_user($uid, $post_id) { ..... }
查询
$s = "select count(grade) cnt, sum(grade) smm from ".$wpdb->prefix."job_ratings where uid='$uid' and awarded='1' and pid='$post_id'";
最终代码
function pricerrtheme_show_rating_star_user($uid, $post_id) {
$concat = '';
$nr_ratings = 0;
global $wpdb;
$s = "select count(grade) cnt, sum(grade) smm from ".$wpdb->prefix."job_ratings where uid='$uid' and awarded='1' and pid='$post_id'";
$r = $wpdb->get_results($s);
if(count($r) > 0)
{
$nr_ratings = $r[0]->cnt;
$sum = $r[0]->smm;
if($nr_ratings > 0)
{
if($sum > 0)
$sdd = ceil($sum/$nr_ratings);
else $sdd = 1;
for($i=1;$i<=$sdd;$i++)
{
$concat .= ' <img src="'.get_bloginfo('template_url').'/images/star_full.png" width="15" />';
}
for($i=$sdd+1;$i<=5;$i++)
{
$concat .= ' <img src="'.get_bloginfo('template_url').'/images/star_empty.png" width="15" />';
}
}
else
{
$concat = '';
for($i=1;$i<=5;$i++)
{
$concat .= ' <img src="'.get_bloginfo('template_url').'/images/star_empty.png" width="15" />';
}
}
}
else
{
$concat = '';
for($i=1;$i<=5;$i++)
{
$concat .= ' <img src="'.get_bloginfo('template_url').'/images/star_empty.png" width="15" />';
}
}
return $concat." (".$nr_ratings.")";
}
希望这有帮助
答案 1 :(得分:1)
KrishCdbry 是我曾经遇到过的最好的一个问题GURU我从来没有见过这么多有才华和经验丰富的编码员,比如 KrishCdbry 最好的部分是他是如此的病人和这个温柔的男人应该得到A +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++