humanmade / related-posts
支持手动覆盖的可扩展相关文章包装器。
1.2.2
2019-01-22 18:17 UTC
Requires (Dev)
- humanmade/coding-standards: ^0.5.0
README
此插件提供以下功能的相关文章简单功能:
- ElasticPress 集成(使用 "类似内容" 查询)
- 手动覆盖相关文章的 Admin UI
安装
composer require humanmade/related-posts
使用
该插件公开了一个函数,该函数返回一系列文章 ID。
HM\Related_Posts\get( int $post_id, array $args = [] )
$post_id 是获取相关内容的文章 ID。
$args 允许你对返回的文章进行一些控制
- int limit:默认为
10
- array post_types:限制结果的文章类型的数组。默认为
[ 'post' ]
- array taxonomies:比较的术语分类数组。默认为
[ 'category' ]
- array terms:
WP_Term
对象的数组,结果将匹配这些术语 - array terms_not_in:不匹配这些术语的
WP_Term
对象的数组 - bool ep_integrate:如果为 true,则使用 ElasticPress 获取结果,默认为
defined( 'EP_VERSION' )
自定义文章类型支持
要将相关文章支持添加到您的自定义文章类型,只需声明以下内容:
add_post_type_support( 'your-custom-post-type', 'hm-related-posts' );
除了精细控制具有相关文章支持的文章类型外,您还可以使用 hm_rp_post_types
过滤器。
add_filter( 'hm_rp_post_types', function ( $post_types ) { // your code goes in here return $post_types; } );
由 Human Made 用 ❤️ 制作