register_post_type【详解】
https://vpura.com/2018/03/30/wp_jiaocheng/code/51/ 说明 r…
https://vpura.com/2018/03/30/wp_jiaocheng/code/51/
说明
register_post_type($post_type,$args)是用于自定义文章类型的函数,在之前有讲过其主要参数,在此,我将该函数的所有参加以及其具体含义进行了归纳,以供大家了解。
用法
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<?php register_post_type( $post_type, $args ) ?>
//示例
function my_custom_post_movie() {
$labels = array(
‘name’ => _x( ‘Movies’, ‘post type 名称’ ),
‘singular_name’ => _x( ‘Movie’, ‘post type 单个 item 时的名称,因为英文有复数’ ),
‘add_new’ => _x( ‘新建电影’, ‘添加新内容的链接名称’ ),
‘add_new_item’ => __( ‘新建一个电影’ ),
‘edit_item’ => __( ‘编辑电影’ ),
‘new_item’ => __( ‘新电影’ ),
‘all_items’ => __( ‘所有电影’ ),
‘view_item’ => __( ‘查看电影’ ),
‘search_items’ => __( ‘搜索电影’ ),
‘not_found’ => __( ‘没有找到有关电影’ ),
‘not_found_in_trash’ => __( ‘回收站里面没有相关电影’ ),
‘parent_item_colon’ => ”,
‘menu_name’ => ‘Movies’
);
$args = array(
‘labels’ => $labels,
‘description’ => ‘我们网站的电影信息’,
‘public’ => true,
‘menu_position’ => 5,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘excerpt’, ‘comments’ ),
‘has_archive’ => true
);
register_post_type( ‘movie’, $args );
}
add_action( ‘init’, ‘my_custom_post_movie’ );
|
参数
$post_type
(string) (必选) 文章类型。(最多20个字符)
Default: 空
$args
(array) (可选) 一个数组参数。
Default: 空
$args – 详细设置:
label – 选填 默认和$post_type一样
labels: 该数组主要是设置wordpress中该文章类型页各种按钮和消息的内容
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
‘name’ – 文章类型的名称(复数)
‘singular_name’ – 单篇文章类型的名称
‘add_new’ – 对应“添加新的文本”
‘add_new_item’ – “添加新帖/新页面”
‘edit_item’ – “编辑帖子/页面”
‘new_item’ – “新贴/新页”
‘view_item’ – “查看帖子/页面”
‘search_items’ – 默认是搜索帖子/搜索页面
‘not_found’ – 默认是没有发现帖子/找不到页面。
‘not_found_in_trash’ – 默认是在垃圾桶中找不到帖子/在垃圾桶中找不到页面。
‘parent_item_colon’ – 此字符串不用于非分层类型。在层次结构中,默认为“父页面:”。
‘menu_name’ – the menu name text. This string is the name to give menu items. Defaults to value of name
‘description’ – 文章类型的简要描述,可以通过以下代码读取:
$obj = get_post_type_object(‘your_post_type_name’);
echo esc_html($ obj-> description)
‘public’ – 控制类型对authors(show_in_nav_menus,show_ui 和reader(exclude_from_search,publicly_queryable)可见的方式。 默认是false
‘publicly_queryable’ – 是否可以在前端执行查询作为parse_request()的一部分。 默认值:public参数的值
‘exclude_from_search’ – 是否从前端搜索结果排除此帖子类型的帖子
‘show_ui’ – 是否在管理员中生成用于管理此帖子类型的默认UI。 * 默认值:public参数的值
‘show_in_menu’ – 在管理菜单中显示帖子类型的位置。show_ui必须是真的。
默认值:show_ui参数的值
* false – 不要在管理菜单中显示
* true – 显示为顶级菜单
* some string – 如果现有的顶级页面,如“tools.php”或“edit.php?post_type = page”,那么这个帖子类型将被放置为子菜单。
‘menu_position’ – 菜单中的位置将显示帖子类型。show_in_menu必须为true。
默认值:null – 默认为以下注释
5 – below Posts
10 – below Media
15 – below Links
20 – below Pages
25 – below comments
60 – below first separator
65 – below Plugins
70 – below Users
75 – below Tools
80 – below Settings
100 – below second separator
‘menu_icon’ – 用于此菜单的图标的URL或iconfont中图标的名称
默认值:null – 默认为帖子图标
‘capability_type’ – 用于构建读取,编辑和删除功能的字符串。可以作为一个数组传递,以便使用这个参数作为基础来构建功能时可以使用替代复数,例如array(‘story’,‘stories’),第一个数组元素将被用于单数形式的能力,第二个数组元素对于复数功能,这不是自动生成的版本,如果没有给出数组将是“故事”。‘capability_type’参数用作构建能力的基础,除非它们使用‘capabilities’参数显式设置。似乎`map_meta_cap`需要设置为false或者为null,以使其工作 。
默认:“post”
‘capabilities’ – 这个帖子类型的功能的数组。
默认值:capability_type用于构造
‘map_meta_cap’ – 是否使用内部默认元功能处理。
默认值:null
如果将其设置为false,则标准管理角色无法编辑帖子类型。然后必须将edit_post功能添加到所有角色以添加或编辑帖子类型。
‘hierarchical’ – Post类型是否是分层的(例如页面)。允许指定父项。‘supports’参数应该包含‘page-attributes’来显示编辑器页面上的父选择框。
默认值:false
‘supports’ – 用于直接调用add_post_type_support()的别名。从3.5开始,布尔值false可以作为值而不是数组传递,以防止缺省(标题和编辑器)行为。
默认值: title and editor
‘title’ 标题
‘editor’ (content) 编辑器
‘author’ 作者
‘thumbnail’ 特色图片
‘excerpt’ 摘抄
‘trackbacks’ 引用通过
‘custom-fields’ 自定义字段
‘comments’ 评论
‘revisions’ 修订–将修改存储
‘page-attributes’ 菜单顺序
‘post-formats’ 添加帖子格式
* 注意:当您使用使用缩略图的自定义帖子类型时,请记住,该主题还支持缩略图或使用add_theme_support功能。
‘register_meta_box_cb’ – 提供在设置编辑表单的元框时调用的回调函数。回调函数使用一个参数$ post,其中包含当前编辑的帖子的WP_Post对象。在回调中执行remove_meta_box()和add_meta_box()调用。
默认值:无
‘taxonomies’ – 一个category或多个post_tag已使用此类型的注册分类法的数组。这可以直接用于调用register_taxonomy_for_object_type()。自定义分类法仍然需要注册register_taxonomy()。
默认值:没有分类
‘permalink_epmask’ – 默认的重写端点位掩码。 默认值:EP_PERMALINK
‘has_archive’ – 启用帖子类型归档。默认情况下,将使用$ post_type作为存档段。默认值:false
‘rewrite’ – 触发此帖子类型的重写操作。为了防止重写,设置为false。默认值:true,并使用$ post_type作为slug
$ args数组
‘slug’=> string自定义永久链接结构块。默认为$ post_type值。应该是可翻译的
‘with_front’=> bool应该使用前置基座添加永久链接结构。(例如:如果你的永久链接结构是/ blog /,那么你的链接将是:false – > / news /,true – > / blog / news /)。默认为true
‘feed’=> bool应该为此帖子类型构建一个feed permalink结构。默认为has_archive值。
‘pages’=> bool应该是永久链接结构提供分页。默认为true
‘ep_mask’=> const 从3.4开始为这个帖子类型分配端点掩码。有关更多信息,请参阅Rewrite API /
‘query_var’ – 设置此帖子类型的query_var键。 默认值:true – 设置为$ post_type false则表示禁用query_var
‘can_export’ – 可以导出此post_type。 默认值:true
‘show_in_nav_menus’ –是否可以在导航菜单中选择post_type。 默认值:public参数的值
‘_builtin – (boolean)’(不是一般用途)这个帖子类型是本地的还是“内置的”post_type。 注意:此Codex条目适用于文档 – 核心开发人员建议您在注册您自己的文章类型时不要使用它。默认值:false
‘false’ – 默认这是一个自定义帖子类型
‘true’ – 这是一个内置的原生帖子类型(帖子,页面,附件,修订版,nav_menu_item)
‘_edit_link’ –(布尔型)(不适用于一般用途)链接以编辑此帖子类型的条目。 注意:此Codex条目适用于文档‘ – ‘核心开发人员建议您在注册您自己的文章类型时不要使用它
默认:‘post.php?post=%d’
|
类别:WordPress开发、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!