以下是代码,第5个,最后一个没有显示在ADMIN CP面板中。所有其他人都工作正常,但当我尝试添加第五个。什么都没有出现。不确定是否有限制或其他东西,似乎不是我读过的。
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'Slides',
array(
'labels' => array(
'name' => __( 'slides' ),
'singular_name' => __( 'slide' )
),
'public' => true,
'has_archive' => true,
)
);
register_post_type( 'Programs',
array(
'labels' => array(
'name' => __( 'programs' ),
'singular_name' => __( 'program' )
),
'public' => true,
'has_archive' => true,
)
);
register_post_type( 'Boards',
array(
'labels' => array(
'name' => __( 'Boards' ),
'singular_name' => __( 'sponsor' )
),
'public' => true,
'has_archive' => true,
)
);
答案 0 :(得分:2)
你的代码工作得很完美,你刚刚在代码中忘记了结束括号}
和slug post类型中的一些错误(小写):
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'slides', // <== here to lowercase (slug)
array(
'labels' => array(
'name' => __( 'Slides' ), // <== here 1st letter uppercase
'singular_name' => __( 'Slide' ) // <== here 1st letter uppercase
),
'public' => true,
'has_archive' => true,
)
);
register_post_type( 'programs', // <== here to lowercase (slug)
array(
'labels' => array(
'name' => __( 'Programs' ), // <== here 1st letter uppercase
'singular_name' => __( 'Program' ) // <== here 1st letter uppercase
),
'public' => true,
'has_archive' => true,
)
);
register_post_type( 'boards', // <== here to lowercase (slug)
array(
'labels' => array(
'name' => __( 'Boards' ),
'singular_name' => __( 'Board' ) // <== here singular
),
'public' => true,
'has_archive' => true,
)
);
} // <== forgetted this
我已经在测试网站上测试了您的代码,甚至是您的自定义帖子&#34; Boards&#34;正在展示和工作:
您可能需要刷新重写规则,方法是执行后端固定链接设置,然后只需单击“保存”即可重新生成与此新帖子类型相关的Wordpress重写规则...
WordPress中的帖子类型是否有限制?
对不同自定义帖子的数量没有限制。试试下面的例子,它在一个非常紧凑的代码中生成10个带有for循环的自定义帖子:
add_action( 'init', 'create_post_type' );
function create_post_type() {
$arr = array('abcdef','bcdefg','cdefgh','defghi','efghij','fghijk','ghijkl','hijklm','ijklmn','jklmno');
for( $i = 0; $i < 10; $i++ ) {
$slug = $arr[$i];
$slugs = $arr[$i].'s';
register_post_type( $slug,
array(
'labels' => array(
'name' => $slugs,
'singular_name' => $slug ),
'public' => true,
'has_archive' => true )
);
}
}
参考文献: