wordpress收费下载资源主题
wordpress付费下载资源插件

WordPress函数add_post_type_support详细用法教程解析

add_post_type_support函数用于为自定义文章类型(custom post types)添加指定的功能。

add_post_type_support函数的语法如下:
add_post_type_support( string $post_type, string|array $feature )

参数说明:
- $post_type:(必填)要为其添加功能的自定义文章类型名称。
- $feature:(必填)要添加的功能的名称,可以是字符串或数组。

下面是add_post_type_support函数的示例用法:

1. 添加缩略图功能:

add_action('init', 'my_custom_post_type');
function my_custom_post_type() {
$args = array(
'public' => true,
'label' => 'Custom Post Type',
'supports' => array( 'title', 'editor', 'thumbnail' )
);
register_post_type( 'custom_post_type', $args );
}

在上面的示例中,我们使用register_post_type函数创建了一个名为custom_post_type的自定义文章类型,并通过'supports'参数指定了需添加的功能,其中包括了'thumbnail',即缩略图功能。

2. 添加自定义分类法(taxonomy)功能:

add_action('init', 'my_custom_taxonomy');
function my_custom_taxonomy() {
$args = array(
'label' => 'Custom Taxonomy',
'rewrite' => array('slug' => 'custom-taxonomy'),
'hierarchical' => true
);
register_taxonomy( 'custom_taxonomy', 'custom_post_type', $args );
add_post_type_support( 'custom_post_type', 'custom_taxonomy' );
}

在上面的示例中,我们使用register_taxonomy函数创建了一个名为custom_taxonomy的自定义分类法,并将其关联到custom_post_type自定义文章类型。然后,我们使用add_post_type_support函数将custom_taxonomy功能添加到custom_post_type自定义文章类型中。

总结:
add_post_type_support函数用于为自定义文章类型添加指定的功能,可以通过字符串或数组的方式指定多个功能。

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情