plenge/wp-postratings-pretty

为您的WordPress网站内容添加AJAX评分系统

安装: 663

依赖项: 0

建议者: 0

安全: 0

星级: 0

关注者: 1

分支: 82

类型:wordpress-plugin

1.0 2017-07-25 11:44 UTC

This package is not auto-updated.

Last update: 2024-09-21 16:04:09 UTC


README

贡献者:GamerZ
捐赠链接:https://lesterchan.net/site/donation/
标签:ratings, rating, postratings, postrating, vote, digg, ajax, post
最低要求:4.2
测试到:4.7
稳定标签:1.84.1

为您的WordPress网站内容添加AJAX评分系统。

描述

用法

  1. 打开 wp-content/themes/<YOUR THEME NAME>/index.php
  2. 您也可以将其放在archive.php、single.php、post.php或page.php中。
  3. 查找:<?php while (have_posts()) : the_post(); ?>
  4. 在以下位置添加(您想显示评分的地方):<?php if(function_exists('the_ratings')) { the_ratings(); } ?>
  • 如果您不希望评分出现在每个帖子/页面中,请不要使用上面的代码。只需在所选帖子/页面内容中输入 [ratings],它将只在该帖子/页面中嵌入评分。
  • 如果您想嵌入其他帖子评分,使用 [ratings id="1"],其中1是要显示的帖子/页面评分的ID。
  • 如果您想嵌入其他帖子评分结果,使用 [ratings id="1" results="true"],其中1是要显示的帖子/页面评分结果的ID。

构建状态

Build Status

开发

https://github.com/lesterchan/wp-postratings-pretty

翻译

http://dev.wp-plugins.org/browser/wp-postratings-pretty/i18n/

致谢

捐赠

我花费了大部分业余时间创建、更新、维护和支持这些插件,如果您真的喜欢我的插件并且可以赞助我一些钱,我将非常感激。如果不可以,请随意使用,没有任何义务。

变更日志

版本 1.84.1

  • 新增:新增 wp_postratings_google_structured_data 过滤器以过滤Google结构化数据。
  • 修复:由于 sanitize_file_name(),unnamed-file.numbers。
  • 修复:生成完整的图像路径,以防止Googlebot 404。

版本 1.84

  • 新增:新增 '%POST_THUMBNAIL%' 模板变量。
  • 新增:新增 'wp_postratings_cookie_expiration' 过滤器。感谢 @ramiy。
  • 新增:新增 'wp_postratings_ratings_image_alt' 过滤器
  • 新增:添加更多元数据itemprops以通过结构化数据测试工具测试
  • 新增:从插件中删除po/mo文件。感谢 @ramiy。
  • 新增:使用 translate.wordpress.org 翻译插件。感谢 @ramiy。
  • 新增:添加phpDocs并更新文件头。感谢 @ramiy。
  • 新增:添加限制投票权给博客成员的功能。感谢 @stephenharris。
  • 修复:使用新的管理员标题层次结构,使用H1、H2、H3标签。感谢 @ramiy。
  • 修复:将*.js文件移动到/js/子文件夹。感谢 @ramiy。
  • 修复:将*.css文件移动到/css/子文件夹。感谢 @ramiy。
  • 修复:将脚本移动到/includes/子文件夹中的单独文件。感谢 @ramiy。
  • 修复:将小部件移动到/includes/子文件夹中的单独文件。感谢 @ramiy。
  • 修复:将短代码移动到/includes/子文件夹中的单独文件。感谢 @ramiy。
  • 修复:将激活钩子移动到/includes/子文件夹中的单独文件。感谢 @ramiy。
  • 修复:将管理函数和钩子移动到/includes/子文件夹中的单独文件。感谢 @ramiy。
  • 修复:将 i18n 加载移动到 /includes/ 子文件夹中的单独文件。感谢 @ramiy。
  • 修复:将 die() 替换为 wp_die() 并将 i18n 添加到字符串。感谢 @ramiy。
  • 修复:更新翻译字符串以避免使用 'post' 作为文章类型。感谢 @ramiy。
  • 修复:微小的翻译字符串修正。感谢 @ramiy。
  • 修复:更新评分小部件。感谢 @ramiy。
  • 修复:加强安全性。感谢 @stephenharris。

版本 1.83.2

  • 修复:在 ratings_most_orderby() 中修复未认证的盲 SQL 注入。感谢 Automattic 的 @Ben Bidner。

版本 1.83.1

  • 修复:从 _ratings_results() 中删除无结果模板。

版本 1.83

  • 新增:添加 'wp_postratings_display_comment_author_ratings' 过滤器。感谢 @ramiy。
  • 修复:移除“正在加载...”,因为 SERP 如果评分位于文章顶部,会索引该文本。
  • 修复:将 'wp_postratings_image_extension' 过滤器移动到 init()。
  • 修复:即使没有评分,也显示标题、datePublished 和图片。
  • 修复:当排序在 URL 中完成时,也显示没有评分的文章。感谢 @talljosh。

版本 1.82

  • 新增:添加 'wp_postratings_image_extension' 过滤器。感谢 @ramiy。
  • 修复:将标题、datePublished、图片添加到 Article Schema 类型。
  • 修复:在 WordPress 4.3 中弃用 PHP4 构造函数。
  • 修复:当 Rich Snippets 关闭时移除 schema 代码。

版本 1.81

  • 新增:添加最差评分 1。感谢 @rafaellop。
  • 新增:检查定义了 RATINGS_IMG_EXT 允许覆盖。
  • 修复:与 WP-Stats 集成。

版本 1.80

  • 新增:在小部件中支持自定义文章类型。
  • 新增:添加 'wp_postratings_process_ratings_user', 'wp_postratings_process_ratings_userid' 和 'wp_postratings_check_rated' 过滤器。
  • 新增:支持 WordPress 多站网络激活。
  • 新增:使用 WordPress 本地的 uninstall.php。

版本 1.79

  • 新增:使用 POST 替代评分。
  • 新增:添加 'wp_postratings_schema_itemtype' 过滤器,以便您可以更改 Schema 类型。请参阅 FAQ 以获取示例。
  • 修复:使用 'is_rtl()' 而不是 $text_direction。

版本 1.78

  • 新增:使用 Dash 图标。
  • 新增:选项关闭 Google Rich Snippets。
  • 修复:使用 SITECOOKIEPATH 而不是 COOKIEPATH。感谢 jbrule。
  • 修复:如果全局 $id 为 0,则使用 get_the_ID()。感谢 instruite。
  • 修复:使用 esc_attr() 和 esc_js() 转义字符。

版本 1.77

  • 新增:添加 %POST_ID% 模板变量。
  • 修复:确保 Google Rich Snippet 仅在主循环中显示,不在小部件中。
  • 修复:从 Google Rich Snippet 中移除 reviewCount。
  • 修复:使评分小部件更优化。
  • 修复:一些小部件模板使用 postratings_template_mostrated 而不是 postratings_template_highestrated。

版本 1.76

  • 修复:如果 update_post_meta() 失败,不再需要 add_post_meta()。
  • 修复:由于缺少 nonce,更新 'Individual Rating Text/Value' 显示不起作用。
  • 修复:在模板中添加 stripslashes() 以移除斜杠。
  • 修复:检查是否为数组,以防止 array_key_exists() 抛出警告。

版本 1.75

  • 将 htmlspecialchars 改为 esc_attr()。感谢 Ryan Satterfield。
  • 将 esc_attr() 改为 wp_kses() 用于 itemprop。感谢 oneTarek。

版本 1.74

  • check_rated_username() 应使用 $user_ID。感谢 Artem Gordinsky。

版本 1.73

版本 1.72 (2013年11月7日)

  • 修复未记录评分。
  • 修复评分日志的排序。

升级通知

截图

  1. 管理员 - 评分日志底部
  2. 管理员 - 评分日志顶部
  3. 管理员 - 评分选项
  4. 管理员 - 评分模板
  5. 评分
  6. 评分悬停

常见问题解答

如何更改 Schema 类型?

<?php  
add_filter( 'wp_postratings_schema_itemtype', 'wp_postratings_schema_itemtype' );  
function wp_postratings_schema_itemtype( $itemtype ) {  
	return 'itemscope itemtype="http://schema.org/Recipe"';  
}  
?>

默认架构类型为 'Article',如果您想将其更改为 'Recipe',则需要使用如上示例代码所示的 wp_postratings_schema_itemtype 过滤器。

如何为谷歌丰富片段添加您的网站标志

<?php  
add_filter( 'wp_postratings_site_logo', 'wp_postratings_site_logo' );  
function wp_postratings_site_logo( $url ) {  
	return 'http://placehold.it/350/150.png';  
}  
?>

默认情况下,插件将使用您的网站页眉图像URL作为您的网站标志。如果您想更改它,需要使用如上示例代码所示的 wp_postratings_site_logo 过滤器。

如何移除评分图像的 alt 和标题文本?

<?php  
add_filter( 'wp_postratings_ratings_image_alt', 'wp_postratings_ratings_image_alt' );  
function wp_postratings_ratings_image_alt( $alt_title_text ) {  
	return '';  
}  
?>

如何显示评论作者评分?

add_filter( 'wp_postratings_display_comment_author_ratings', '__return_true' );

默认情况下,不显示评论作者评分。如果您想显示评分,需要使用如上示例代码所示的 wp_postratings_display_comment_author_ratings 过滤器。

如何使用 PNG 图像而不是 GIF 图像?

function custom_rating_image_extension() {
    return 'png';
}
add_filter( 'wp_postratings_image_extension', 'custom_rating_image_extension' );

默认图像扩展名为 'gif',如果您想将其更改为 'png',需要使用如上示例代码所示的 wp_postratings_image_extension 过滤器。

如何更改cookie过期时间?

function custom_rating_cookie_expiration() {
	return strtotime( 'tomorrow' ) ;
}
add_filter( 'wp_postratings_cookie_expiration', 'custom_rating_cookie_expiration', 10, 0 );

默认cookie过期时间为 'time() + 30000000',如果您想更改过期时间长度,需要使用如上示例代码所示的 wp_postratings_cookie_expiration 过滤器。

wp-postratings-pretty 如何加载 CSS?

  • wp-postratings-pretty 会从您的主题 CSS 目录加载 postratings-css.css,如果存在的话。
  • 如果不存在,它将仅加载 wp-postratings-pretty 伴随的默认 'postratings-css.css'。
  • 这将允许您在不担心覆盖您创建的评分样式的情况下升级 wp-postratings-pretty。

如何使用小部件与评分统计结合使用?

  1. 转到 WP-Admin -> 外观 -> 小部件
  2. 小部件名称为评分。

显示最低评分的文章

<?php if (function_exists('get_lowest_rated')): ?>
	<ul>
		<?php get_lowest_rated(); ?>
	</ul>
<?php endif; ?>
  • 默认:get_lowest_rated('both', 0, 10)
  • 'both' 值将显示评分最低的文章和页面。
  • 如果您只想显示评分最低的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最低的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个最低评分的文章/页面。

按标签显示最低评分的文章

<?php if (function_exists('get_lowest_rated_tag')): ?>
	<ul>
		<?php get_lowest_rated_tag(TAG_ID); ?>
	</ul>
<?php endif; ?>
  • 默认:get_lowest_rated_tag(TAG_ID, 'both', 0, 10)
  • 用您的标签 ID 替换 TAG_ID。如果您想它跨越多个分类,请将 TAG_ID 替换为 array(1, 2),其中 1 和 2 是您的分类 ID。
  • 'both' 值将显示评分最低的文章和页面。
  • 如果您只想显示评分最低的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最低的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个最低评分的文章/页面。

在分类中显示最低评分的文章

<?php if (function_exists('get_lowest_rated_category')): ?>
	<ul>
		<?php get_lowest_rated_category(CATEGORY_ID); ?>
	</ul>
<?php endif; ?>
  • 默认:get_lowest_rated_category(CATEGORY_ID, 'both', 0, 10)
  • 用您的分类 ID 替换 CATEGORY_ID。如果您想它跨越多个分类,请将 CATEGORY_ID 替换为 array(1, 2),其中 1 和 2 是您的分类 ID。
  • 'both' 值将显示评分最低的文章和页面。
  • 如果您只想显示评分最低的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最低的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个最低评分的文章/页面。

显示最高评分的文章

<?php if (function_exists('get_highest_rated')): ?>
	<ul>
		<?php get_highest_rated(); ?>
	</ul>
<?php endif; ?>
  • 默认:get_highest_rated('both', 0, 10)
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

按标签显示最高评分的文章

<?php if (function_exists('get_highest_rated_tag')): ?>
	<ul>
		<?php get_highest_rated_tag(TAG_ID); ?>
	</ul>
<?php endif; ?>
  • 默认:get_highest_rated_tag(TAG_ID, 'both', 0, 10)
  • 用您的标签 ID 替换 TAG_ID。如果您想它跨越多个分类,请将 TAG_ID 替换为 array(1, 2),其中 1 和 2 是您的分类 ID。
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

在分类中显示最高评分的文章

<?php if (function_exists('get_highest_rated_category')): ?>
	<ul>
		<?php get_highest_rated_category(CATEGORY_ID); ?>
	</ul>
<?php endif; ?>
  • 默认:get_highest_rated_category(CATEGORY_ID, 'both', 0, 10)
  • 用您的分类 ID 替换 CATEGORY_ID。如果您想它跨越多个分类,请将 CATEGORY_ID 替换为 array(1, 2),其中 1 和 2 是您的分类 ID。
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

在给定时间段内显示最高评分的文章

<?php if (function_exists('get_highest_rated_range')): ?>
	<ul>
		<?php get_highest_rated_range('1 day'); ?>
	</ul>
<?php endif; ?>
  • 默认:get_highest_rated_range('1 day', 'both', 10)
  • '1 day' 将是您想要的范围。您可以使用 '2 days'、'1 month' 等。
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

显示最高评分的文章

<?php if (function_exists('get_most_rated')): ?>
	<ul>
		<?php get_most_rated(); ?>
	</ul>
<?php endif; ?>
  • 默认:get_most_rated('both', 0, 10)
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

显示某一分类中最受好评的帖子

<?php if (function_exists('get_most_rated_category')): ?>
	<ul>
		<?php get_most_rated_category(CATEGORY_ID); ?>
	</ul>
<?php endif; ?>
  • 默认:get_most_rated_category(CATEGORY_ID, 'both', 0, 10)
  • 用您的分类 ID 替换 CATEGORY_ID。如果您想它跨越多个分类,请将 CATEGORY_ID 替换为 array(1, 2),其中 1 和 2 是您的分类 ID。
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

显示在给定时间段内最受好评的帖子

<?php if (function_exists('get_most_rated_range')): ?>
	<ul>
		<?php get_most_rated_range('1 day'); ?>
	</ul>
<?php endif; ?>
  • 默认:get_most_rated_range('1 day', 'both', 10)
  • '1 day' 将是您想要的范围。您可以使用 '2 days'、'1 month' 等。
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

显示得分最高的帖子

<?php if (function_exists('get_highest_score')): ?>
	<ul>
		<?php get_highest_score(); ?>
	</ul>
<?php endif; ?>
  • 默认:get_highest_score('both', 0, 10)
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

显示某一分类中得分最高的帖子

<?php if (function_exists('get_highest_score_category')): ?>
	<ul>
		<?php get_highest_score_category(CATEGORY_ID); ?>
	</ul>
<?php endif; ?>
  • 默认:get_highest_score_category(CATEGORY_ID, 'both', 0, 10)
  • 用您的分类 ID 替换 CATEGORY_ID。如果您想它跨越多个分类,请将 CATEGORY_ID 替换为 array(1, 2),其中 1 和 2 是您的分类 ID。
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 0 表示显示文章之前所需的最小投票数。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

显示在给定时间段内得分最高的帖子

<?php if (function_exists('get_highest_score_range')): ?>
	<ul>
		<?php get_highest_score_range('1 day'); ?>
	</ul>
<?php endif; ?>
  • 默认:get_highest_score_range('1 day', 'both', 10)
  • '1 day' 将是您想要的范围。您可以使用 '2 days'、'1 month' 等。
  • 'both' 值将显示评分最高的文章和页面。
  • 如果您只想显示评分最高的文章,请将 'both' 替换为 'post'。
  • 如果您只想显示评分最高的页面,请将 'both' 替换为 'page'。
  • 值 10 将仅显示前 10 个评分最高的文章/页面。

排序得分最高/最低的帖子

  • 可以使用以下代码:<?php query_posts( array( 'meta_key' => 'ratings_average', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); ?>
  • 或将变量传递到URL中: http://yoursite.com/?r_sortby=highest_rated&amp;r_orderby=desc
  • 如果想显示得分最低的帖子,可以将desc替换为asc。

排序最受/最不受好评的帖子

  • 可以使用以下代码:<?php query_posts( array( 'meta_key' => 'ratings_users', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); ?>
  • 或将变量传递到URL中: http://yoursite.com/?r_sortby=most_rated&amp;r_orderby=desc
  • 如果想显示得分最低的帖子,可以将desc替换为asc。