本初学者教程包含所有PHP代码,您只需将它们复制并粘贴在子主题functions.php文件的末尾即可。
其中包括多个代码段,以自定义希望评级图标显示的位置。
安装完 WP Postratings插件 然后,您可以使用Notepad ++之类的代码编辑器,将以下任何PHP代码段添加到子主题函数文件的末尾。
单帖标题后
add_action( 'genesis_entry_header', 'wp_post_ratings_header' );
function wp_post_ratings_header() {
if( function_exists('the_ratings') && is_singular('post')) {
the_ratings();
}
}
单帖标题后& Archives
add_action( 'genesis_entry_header', 'wp_post_ratings_header_archives' );
function wp_post_ratings_header_archives() {
if( function_exists('the_ratings') ) {
the_ratings();
}
}
单篇文章以下内容
add_action( 'genesis_entry_footer', 'wp_post_ratings_footer' );
function wp_post_ratings_footer() {
if( function_exists('the_ratings') && is_singular('post')) {
the_ratings();
}
}
单篇文章以下内容& Archives
add_action( 'genesis_entry_footer', 'wp_post_ratings_footer_archives' );
function wp_post_ratings_footer_archives() {
if( function_exists('the_ratings')) {
the_ratings();
}
}
获得最低评分
add_action( 'genesis_entry_footer', 'lowest_wp_post_ratings' );
function lowest_wp_post_ratings() {
if (function_exists('get_lowest_rated')) {
get_lowest_rated();
}
}
获得最低评分的标签
将以下代码中的TAG_ID替换为标签的ID。
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);
}
}
获得最低评分类别
将以下代码中的CATEGORY_ID替换为您类别的ID。
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);
}
}
获得最高评分
add_action( 'genesis_entry_footer', 'highest_wp_post_ratings' );
function highest_wp_post_ratings() {
if ( function_exists('get_highest_rated')) {
get_highest_rated();
}
}
获得最高评分的标签
将以下代码中的TAG_ID替换为标签的ID。
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);
}
}
获得最高评分类别
将以下代码中的CATEGORY_ID替换为您类别的ID。
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);
}
}
获得最高额定范围
将以下代码中的1天替换为天数。
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');
}
}
评分最高的帖子
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();
}
}
类别中评分最高的帖子
将以下代码中的CATEGORY_ID替换为您类别的ID。
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);
}
}
在指定时期内评分最高
将以下代码中的1天替换为天数。
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');
}
}
最高分
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();
}
}
类别中得分最高的帖子
将以下代码中的CATEGORY_ID替换为您类别的ID。
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);
}
}
在给定时间内得分最高的职位
将以下代码中的1天替换为天数。
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');
}
}
如何更改架构类型
add_filter('wp_postratings_schema_itemtype', 'wp_postratings_schema_itemtype');
function wp_postratings_schema_itemtype($itemtype) {
return 'itemscope itemtype="http://schema.org/Recipe"';
}
这篇文章基于以下问题:
我需要在index.php文件中插入特定的代码。
但是Genesis子主题不包含index.php文件。
我该怎么办?
发表评论
你一定是 登录 发表评论。