php 自定义帖子类型注册

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 自定义帖子类型注册相关的知识,希望对你有一定的参考价值。

<?php echo get_post_type_object(get_post_type(get_the_ID()))->labels->name; ?>

add_action('init', 'add_new_post_type');
function add_new_post_type()
{

	register_taxonomy( 'city', array( 'stops', 'attractions' ), array( 'label' => 'City', 'hierarchical' => true, 'rewrite' => array( 'hierarchical' => true ), 'query_var' => true ) );

	register_post_type(
		'news',
		array(
		   'labels' => array(
			  'name' => 'News',
			  'singular_name' => 'News',
			  'add_new' => 'Add News',
			  'add_new_item' => 'Add New News',
			  'edit_item' => 'Edit News',
			  'new_item' => 'New News',
			  'all_items' => 'All News',
			  'view_item' => 'View News',
			  'search_items' => 'Search News',
			  'not_found' =>  'No News found',
			  'not_found_in_trash' => 'No News found in Trash',
			  'parent_item_colon' => '',
			  'menu_name' => 'News'
			),
		   'public' => true,
		   'has_archive' => true,
		   'show_ui' => true,
		   'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail', 'excerpt', 'revisions' )
		)
	);
 

}

add_action('init', 'add_new_post_type');
function add_new_post_type(){
 register_post_type('news',
                   array(
                        'label' => 'News',
                        'description' => '',
                        'public' => true,
                        'show_ui' => true,
                        'show_in_menu' => true,
                        'capability_type' => 'post',
                        'hierarchical' => false,
                        'rewrite' => array('slug' => ''),
                        'query_var' => true,
                        'hierarchical' => true,
                        'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes'),
                        'labels' => array (
                                        'name' => 'News',
                                        'singular_name' => '',
                                        'menu_name' => 'News',
                                        'name_admin_bar'=> 'News',
                                        'add_new' => 'Add News',
                                        'add_new_item' => 'Add New News',
                                        'edit' => 'Edit',
                                        'edit_item' => 'Edit News',
                                        'new_item' => 'New News',
                                        'view' => 'View News',
                                        'view_item' => 'View News',
                                        'search_items' => 'Search News',
                                        'not_found' => 'No News Found',
                                        'not_found_in_trash' => 'No News Found in Trash',
                                        'parent' => 'Parent News',)
                        ) );
 register_taxonomy('newscategories', 'news', array('label' => 'News-Categories',
      'hierarchical' => true,
      'query_var' => true,
      'rewrite' => array('slug' => 'newscategories')));
}

以上是关于php 自定义帖子类型注册的主要内容,如果未能解决你的问题,请参考以下文章

php 注册后过滤自定义帖子类型

php 注册多个自定义帖子类型CPT

php 注册多个自定义帖子类型CPT

php 注册自定义帖子类型和分类

php 注册多个自定义帖子类型

php 注册自定义帖子类型