我已经为评级创建了自定义代码,而不是为帖子类型创建的代码,这可能会对您有所帮助。
第一步:-模板文件
<!-- begin content -->
<div id="content-wrap" class="top_pad review-planner" >
<div class="review-block">
<div class="container">
<h2><?php echo get_field(\'sub_title\'); ?></h2>
<div class="all-list" style="display:none;">
<?php if(get_field(\'list_title\')) { ?>
<span class="title"><?php echo get_field(\'list_title\'); ?></span>
<?php } ?>
<ul class="list-item">
<li class="service"><span>Service:<i></i></span></li>
<li class="service2"><span>Uitsraling:<i></i></span></li>
<li class="service3"><span>Ligging:<i></i></span></li>
<li class="service4"><span>Eten&drinken:<i></i></span></li>
<li class="service5"><span>Parkeren:<i></i></span></li>
<li class="service6"><span>Prijs/kwaliteit:<i></i></span></li>
</ul>
<a class="reservBtn"><span>Schrijf een review</span></a>
</div>
</div>
</div>
<div class="user-reviews">
<div id="ajaxData">
<?php query_posts(\'post_type=reviews&showposts=-1\');
if (have_posts()) : $i =1; while (have_posts()) : the_post();
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div class="publish-review">
<div class="icon" style="background:url(<?php if($url) { ?><?php echo $url; ?><?php } else { ?><?php bloginfo(\'template_url\'); ?>/images/ic.png<?php } ?>) no-repeat center center; background-size:cover;" >
</div>
<div class="text-right">
<h2><span><?php the_title(); ?></span> <cite class="rating"></cite> <i>9,7</i><small><?php the_time(\'j F Y\') ?></small></h2>
<div class="desc">
<p><?php echo get_field(\'description\'); ?></p>
</div>
<ul>
<?php if(get_field(\'service_rating\')) { ?>
<li class="service">Service: <i><?php echo get_field(\'service_rating\'); ?></i></li>
<?php } ?>
<?php if(get_field(\'uitsraling_rating\')) { ?>
<li class="service2">Uitsraling: <i><?php echo get_field(\'uitsraling_rating\'); ?></i></li>
<?php } ?>
<?php if(get_field(\'ligging_rating\')) { ?>
<li class="service3">Ligging: <i><?php echo get_field(\'ligging_rating\'); ?></i></li>
<?php } ?>
<?php if(get_field(\'eten&drinken_rating\')) { ?>
<li class="service4">Eten&drinken: <i><?php echo get_field(\'eten&drinken_rating\'); ?></i></li>
<?php } ?>
<?php if(get_field(\'parkeren_rating\')) { ?>
<li class="service5">Parkeren: <i><?php echo get_field(\'parkeren_rating\'); ?></i></li>
<?php } ?>
<?php if(get_field(\'prijskwaliteit_rating\')) { ?>
<li class="service6"> Prijs/kwaliteit: <i><?php echo get_field(\'prijskwaliteit_rating\'); ?></i></li>
<?php } ?>
</ul>
</div>
</div>
<?php endwhile; wp_reset_query(); endif; ?>
</div>
</div>
</div>
<?php include \'reviewform.php\'; ?>
<!-- finish content -->
jQuery(文档)。就绪(函数(){
jQuery(\'.header-wrap\').click(function(event) {
event.stopPropagation();
});
setTimeout(function() {
jQuery(\'.all-list\').fadeIn();
jQuery(\'#content-wrap\').trigger(\'click\');
}, 1000);
jQuery(\'.review-block .all-list ul.list-item li\').each(function() {
var ffc = jQuery(this).find(\'span i\').text();
if (jQuery(this).find(\'span i\').text() == "NaN") {
jQuery(this).hide();
}
});
jQuery(\'#content-wrap\').click(function() {
var url = "<?php bloginfo(\'template_url\'); ?>/loadData.php";
jQuery.ajax({
type: "POST",
url: url,
data: "",
my_option: \'sucomp\',
success: function(data) {
jQuery(\'#ajaxData\').html(data);
var szs = jQuery(\'.user-reviews .publish-review\').size();
var szs2 = szs * 10
serv = [];
serv2 = [];
serv3 = [];
serv4 = [];
serv5 = [];
serv6 = [];
var a1 = 0;
var a2 = 0;
var a3 = 0;
var a4 = 0;
var a5 = 0;
var a6 = 0;
jQuery(\'.user-reviews .publish-review\').each(function(m) {
var comvar = 0;
var common = [];
jQuery(this).find(\'.text-right ul li\').each(function() {
if (jQuery(this).hasClass(\'service\')) {
var ths = jQuery(this).find(\'i\').text();
serv.push(ths);
}
if (jQuery(this).hasClass(\'service2\')) {
var ths = jQuery(this).find(\'i\').text();
serv2.push(ths);
}
if (jQuery(this).hasClass(\'service3\')) {
var ths = jQuery(this).find(\'i\').text();
serv3.push(ths);
}
if (jQuery(this).hasClass(\'service4\')) {
var ths = jQuery(this).find(\'i\').text();
serv4.push(ths);
}
if (jQuery(this).hasClass(\'service5\')) {
var ths = jQuery(this).find(\'i\').text();
serv5.push(ths);
}
if (jQuery(this).hasClass(\'service6\')) {
var ths = jQuery(this).find(\'i\').text();
serv6.push(ths);
}
var ths2 = jQuery(this).find(\'i\').text();
common.push(ths2);
});
common.forEach(function(ele, key) {
comvar += parseInt(ele);
});
comvar2 = comvar / 60;
coml2 = comvar2 / 100 * 1000;
console.log(coml2);
jQuery(this).find(\'.text-right h2\').find(\'i\').text(coml2.toFixed(1).replace(".", \',\'));
var pars = parseFloat(coml2);
var divd = pars / 100;
var runds = divd * 1000;
var pieces = runds.toFixed(0);
rund = pieces;
//alert(rund);
function addScore(score, $domElement) {
jQuery("<span class=\'stars-container\'>")
.addClass("stars-" + score.toString())
.text("★★★★★")
.appendTo($domElement);
jQuery("head").append(jQuery(\'<style>.stars-\' + rund + \':after { width:\' + rund + \'%; }</style>\'));
}
addScore(rund, jQuery("#fixture-" + m));
});
serv.forEach(function(ele, key) {
a1 += parseInt(ele);
});
sp1 = a1 / szs2;
tot1 = sp1 / 100 * 1000;
serv2.forEach(function(ele, key) {
a2 += parseInt(ele);
});
sp2 = a2 / szs2;
tot2 = sp2 / 100 * 1000;
serv3.forEach(function(ele, key) {
a3 += parseInt(ele);
});
sp3 = a3 / szs2;
tot3 = sp3 / 100 * 1000;
serv4.forEach(function(ele, key) {
a4 += parseInt(ele);
});
sp4 = a4 / szs2;
tot4 = sp4 / 100 * 1000;
serv5.forEach(function(ele, key) {
a5 += parseInt(ele);
});
sp5 = a5 / szs2;
tot5 = sp5 / 100 * 1000;
serv6.forEach(function(ele, key) {
a6 += parseInt(ele);
});
sp6 = a6 / szs2;
tot6 = sp6 / 100 * 1000;
jQuery(\'.review-block .all-list ul.list-item li\').each(function() {
if (jQuery(this).hasClass(\'service\')) {
jQuery(this).find(\'i\').text(tot1.toFixed(1).replace(".", \',\'));
}
if (jQuery(this).hasClass(\'service2\')) {
jQuery(this).find(\'i\').text(tot2.toFixed(1).replace(".", \',\'));
}
if (jQuery(this).hasClass(\'service3\')) {
jQuery(this).find(\'i\').text(tot3.toFixed(1).replace(".", \',\'));
}
if (jQuery(this).hasClass(\'service4\')) {
jQuery(this).find(\'i\').text(tot4.toFixed(1).replace(".", \',\'));
}
if (jQuery(this).hasClass(\'service5\')) {
jQuery(this).find(\'i\').text(tot5.toFixed(1).replace(".", \',\'));
}
if (jQuery(this).hasClass(\'service6\')) {
jQuery(this).find(\'i\').text(tot6.toFixed(1).replace(".", \',\'));
}
})
},
complete: function() {
jQuery(\'.review-block .all-list ul.list-item li\').each(function() {
var ffc = jQuery(this).find(\'span i\').text();
if (jQuery(this).find(\'span i\').text() == "NaN") {
jQuery(this).hide();
}
});
}
});
return false;
});
})