php - WordPress 发布评级显示位置更改
问题描述
我是一名新开发人员。此代码使用表单插件来显示平均评分及其运行良好。但其显示评级高于 WP 内容。我想在我的博客页面和单页的几个特定位置显示评级。我怎样才能做到这一点?
add_filter( 'the_content', 'ci_comment_rating_display_average_rating' );
function ci_comment_rating_display_average_rating( ) {
global $post;
if ( false === ci_comment_rating_get_average_ratings( $post->ID ) ) {
return $content;
}
$stars = '';
$average = ci_comment_rating_get_average_ratings( $post->ID );
for ( $i = 1; $i <= $average + 1; $i++ ) {
$width = intval( $i - $average > 0 ? 20 - ( ( $i - $average ) * 20 ) : 20 );
if ( 0 === $width ) {
continue;
}
$stars .= '<span style="overflow:hidden; width:' . $width . 'px" class="dashicons dashicons-star-filled"></span>';
if ( $i - $average > 0 ) {
$stars .= '<span style="overflow:hidden; position:relative; left:-' . $width .'px;" class="dashicons dashicons-star-empty"></span>';
}
}
$custom_content = '<p class="average-rating">This post\'s average rating is:-- ' . $average .' ' . $stars .'</p>';
$custom_content .= $content;
return $custom_content;
}
解决方案
推荐阅读
- python - 如何在 Django HTML 中刷新图像
- r - 在 R 中组合时间步长
- java - 从给定的未排序整数数组中查找最长连续元素序列的长度
- scala - scala - 读取时删除
- ios - 使用 @State 解析为在所有存储属性初始化之前使用的“自我”
- python - matplotlib 不尊重 zorder
- python - Mock.assert_has_calls() 没有按预期工作
- azure-cosmosdb - 更新 CRM 字段时逻辑应用程序出错
- php - php - 克隆输入字段后获取文件数据
- c# - 当手动运行与在服务器上运行时,SSIS 中的 Shell32 GetDetailsOf 调用返回不同的结果