• 跳至主要导航
  • 跳到主要内容
  • 跳到主要侧边栏

WP站点

2663

原始创世纪教程和5000多个保证代码

片段

  • 支持
  • 通讯
  • 影片
  • 登录

高级会员? -请求自定义代码

在创世纪中自定义WP帖子评级的17种方法

本初学者教程包含所有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文件。
我该怎么办?

读者互动

发表评论 取消回复

你一定是 登录 发表评论。

主侧边栏

PHP代码

template_include

get_body_class

如果别的

数组

class_exists

前言

冲刺

add_action

打印

变量

广告 · WPEngine · 创世记 · 登录

  • 高级会员的工作方式
  • 报名
  • 支持
  • 订阅详细信息/发票
  • 标记教程
  • 访问下载问题
  • <section id="Fv0bXJp" class="FFTkQVk"></section>
      <th class="QYPN3UO"></th><li id="ryA04HQ"></li>

      • <th class="ei4xUQx"></th>


        <menu class="Ojz7zsG"><b class="pC5F22e"><li id="diofymr" class="dUCkGu7"></li></b></menu>



        <strike class="eLr9R9S"><optgroup class="xs3kMxJ"><acronym class="UJJzUok"></acronym></optgroup></strike>