WordPress自定义文章类型删除编辑区功能函数:remove_post_type_support

WordPress函数remove_post_type_support用于删除自定义文章类型编辑区功能。 remove_post_type_support( string $post_type, string $feature ) 函数参数$post_type 字符串 自定义文章类型 $feature 字符串或数组 需要删除的功能,例如:title、editor、comments、revisions、trackbacks、author、excerpt、page-attributes、thumbnail、custom-fields、and post-formats …

WordPress自定义文章类型添加编辑区功能函数:add_post_type_support

WordPress函数add_post_type_support用于为自定义文章类型编辑区添加功能。 add_post_type_support( string $post_type, string|array $feature, mixed $args ) 函数参数$post_type 字符串 自定义文章类型 $feature 字符串或数组 需要添加的功能,例如:title、editor、comments、revisions、trackbacks、author、excerpt、page-attributes、thumbnail、custom-fields、and post-formats …

WordPress自定义文章类型归档页标题函数:post_type_archive_title

WordPress函数post_type_archive_title用于在自定义文章类型归档页输出标题,通常在archive-{$post_type}.php模板中使用。 post_type_archive_title( string $prefix = '', bool $display = true ) 函数参数$prefix …

WordPress判断是否指定文章类型归档页函数:is_post_type_archive

WordPress函数is_post_type_archive用于判断是否指定的文章类型归档页。 is_post_type_archive( string|string[] $post_types = '' ) 函数参数$post_types 字符串 指定文章类型 函数使用示例<?php if ( is_post_type_archive() ) { ?> <h1><?php post_type_archive_title(); ?></h1> <?php } ?> 扩展阅读is_post_type_archive()函数位于:wp-includes/query.php …

WordPress注册文章类型函数:register_post_type

WordPress函数register_post_type用于注册新的文章类型,不应该在init动作前挂载,所有分类法都通过$taxonomies参数注册,以确保在使用诸如“parse_query”或“pre_get_posts”之类的钩子时的一致性。 …

WordPress检测分类法项目是否存在函数:term_exists

WordPress函数term_exists用于检测分类法项目是否存在。 term_exists( int|string $term, string $taxonomy = '', int $parent = null ) 函数参数$term 字符串或整数 分类法项目的ID、别名或名称 $taxonomy 字符串 分类法名称,如果不指定,默认检测分类法category,返回检测的term ID,如果指定分类法名称,返回包含term_id和term_taxonomy_id的数组 …

WordPress插入分类法函数:wp_insert_term

WordPress函数wp_insert_term用于插入一个分类法项目 wp_insert_term( string $term, string $taxonomy, array|string $args = array() ) 函数参数$term 字符串 分类名称 $taxonomy 字符串 分类法名称 $args 数组或字符串 分类的参数,可用值如下: alias_of:别名; description:分类的简要描述; parent:如果指定分类法支持层级,可以对创建的分类指定父分类; slug:别名。 函数返回值插入分类成功返回包含term_id和term_taxonomy_id的数组,失败返回WP_Error …

WordPress根据文章ID获取分类法对象函数:wp_get_object_terms

WordPress函数wp_get_object_terms根据文章的ID获取分类法对象,主要在自定义分类法时使用,获取Category可以使用get_the_category()函数。 wp_get_object_terms( int|int[] $object_ids, string|string[] $taxonomies, array|string $args = array() ) 函数参数$object_ids …

WordPress获取多个分类法对象函数:get_terms

WordPress函数get_terms根据WP_Term_Query参数获取分类法对象,返回多个分类数据。 get_terms( array|string $args = array(), array|string $deprecated = '' ) 函数参数$args 数组,参数可用值参考get_categories()函数的$args参数说明 函数返回值Array ( [0] => WP_Term Object ( [term_id] => 2 [name] => 开发 [slug] => develop [term_group] => 0 [term_taxonomy_id] => 2 [taxonomy] => category [description] => [parent] => 1 [count] => 100 [filter] => raw ) [1] => WP_Term Object ( [term_id] => 3 [name] => 教程 [slug] => tutorials [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => category [description] => [parent] => 1 [count] => 220 [filter] => raw ) ...... ) 函数使用示例$categories = get_terms( array( 'taxonomy' => 'category', 'parent' => 1 ) ); foreach($categories as $category) { echo '<li><a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>'; } 扩展阅读get_terms()函数位于:wp-includes/taxonomy.php …

WordPress获取分类法所有子级函数:get_term_children

WordPress函数get_term_children用于获取指定分类法的所有子级,例如:获取某个分类的所有子分类,该函数返回所有分类法子级的ID。 get_term_children( int $term_id, string $taxonomy ) 函数参数$term_id …