This tutorial for beginners includes all the PHP code you simply copy and paste at the end of your child themes functions.php file.
Included are multiple code snippets to customize the position of where you want the ratings icons to display.
Once you install the WP Postratings plugin by Lester Chan, you can then add any of the following PHP snippets to the end of your child themes functions file using a code editor like Notepad++.
After Title On Single Posts
add_action( 'genesis_entry_header', 'wp_post_ratings_header' );
function wp_post_ratings_header() {
if( function_exists('the_ratings') && is_singular('post')) {
the_ratings();
}
}
After Title On Single Posts & Archives
add_action( 'genesis_entry_header', 'wp_post_ratings_header_archives' );
function wp_post_ratings_header_archives() {
if( function_exists('the_ratings') ) {
the_ratings();
}
}
Below Content On Single Posts
add_action( 'genesis_entry_footer', 'wp_post_ratings_footer' );
function wp_post_ratings_footer() {
if( function_exists('the_ratings') && is_singular('post')) {
the_ratings();
}
}
Below Content On Single Posts & Archives
add_action( 'genesis_entry_footer', 'wp_post_ratings_footer_archives' );
function wp_post_ratings_footer_archives() {
if( function_exists('the_ratings')) {
the_ratings();
}
}
Get Lowest Rated
add_action( 'genesis_entry_footer', 'lowest_wp_post_ratings' );
function lowest_wp_post_ratings() {
if (function_exists('get_lowest_rated')) {
get_lowest_rated();
}
}
Get Lowest Rated Tag
Replace TAG_ID in the following code with the I.D of your tag.
add_action( 'genesis_entry_footer', 'lowest_wp_post_ratings' );
function lowest_wp_post_ratings() {
if (function_exists('get_lowest_rated_tag')) {
get_lowest_rated_tag(TAG_ID);
}
}
Get Lowest Rated Category
Replace CATEGORY_ID in the following code with the I.D of your category.
add_action( 'genesis_entry_footer', 'lowest_wp_post_ratings' );
function lowest_wp_post_ratings() {
if (function_exists('get_lowest_rated_tag')) {
get_lowest_rated_tag(TAG_ID);
}
}
Get Highest Rated
add_action( 'genesis_entry_footer', 'highest_wp_post_ratings' );
function highest_wp_post_ratings() {
if ( function_exists('get_highest_rated')) {
get_highest_rated();
}
}
Get Highest Rated Tag
Replace TAG_ID in the following code with the I.D of your tag.
add_action( 'genesis_entry_footer', 'highest_wp_post_ratings' );
function highest_wp_post_ratings() {
if (function_exists('get_lowest_rated_tag')) {
get_highest_rated_tag(TAG_ID);
}
}
Get Highest Rated Category
Replace CATEGORY_ID in the following code with the I.D of your category.
add_action( 'genesis_entry_footer', 'highest_wp_post_ratings' );
function highest_wp_post_ratings() {
if (function_exists('get_highest_rated_category')) {
get_highest_rated_tag(Category_ID);
}
}
Get Highest Rated Range
Replace 1 day in the following code with the number of days.
add_action( 'genesis_entry_footer', 'highest_range_wp_post_ratings' );
function highest_range_wp_post_ratings() {
if (function_exists('get_highest_rated_range')) {
get_highest_rated_range('1 day');
}
}
Most Rated Post
add_action( 'genesis_before_loop', 'most_rated_wp_post_ratings' );
function most_rated_wp_post_ratings() {
if (function_exists('get_most_rated')) {
get_most_rated();
}
}
Most Rated Post In A Category
Replace CATEGORY_ID in the following code with the I.D of your category.
add_action( 'genesis_entry_footer', 'most_rated_wp_post_ratings' );
function most_rated_wp_post_ratings() {
if ( function_exists('get_most_rated_category')) {
get_most_rated_category(CATEGORY_ID);
}
}
Most Rated Within A Given Period
Replace 1 day in the following code with the number of days.
add_action( 'genesis_entry_footer', 'most_rated_wp_post_ratings' );
function most_rated_wp_post_ratings() {
if ( function_exists('get_most_rated_range')) {
get_most_rated_range('1 day');
}
}
Highest Score Post
add_action( 'genesis_entry_footer', 'highest_score_wp_post_ratings' );
function highest_score_wp_post_ratings() {
if ( function_exists('get_highest_score')) {
get_highest_score();
}
}
Highest Score Post in Category
Replace CATEGORY_ID in the following code with the I.D of your category.
add_action( 'genesis_entry_footer', 'highest_score_category_wp_post_ratings' );
function highest_score_category_wp_post_ratings() {
if ( function_exists('get_highest_score_category')) {
get_highest_score_category(CATEGORY_ID);
}
}
Highest Score Post Within A Given Period
Replace 1 day in the following code with the number of days.
add_action( 'genesis_entry_footer', 'highest_score_range_wp_post_ratings' );
function highest_score_range_wp_post_ratings() {
if ( function_exists('get_highest_score_range')) {
get_highest_score_range('1 day');
}
}
How To Change Schema Type
add_filter('wp_postratings_schema_itemtype', 'wp_postratings_schema_itemtype');
function wp_postratings_schema_itemtype($itemtype) {
return 'itemscope itemtype="http://schema.org/Recipe"';
}
This post is based on this question:
I need to insert specific code in the index.php file.
But Genesis child themes do not include a index.php file.
What do I do?
Was This Tutorial Helpful?