php 注册自定义帖子类型

Posted

tags:

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

<?php
// Register articles Post Type

function register_cpt_articles() {
	$labels = array(
		'name'               => _x( 'Articles', 'article' ),
		'singular_name'      => _x( 'Article', 'article' ),
		'add_new'            => _x( 'Add new', 'article' ),
		'add_new_item'       => _x( 'Add new article', 'article' ),
		'edit_item'          => _x( 'Edit article', 'article' ),
		'new_item'           => _x( 'New new article', 'article' ),
		'view_item'          => _x( 'View article', 'article' ),
		'search_items'       => _x( 'Search articles', 'article' ),
		'not_found'          => _x( 'No articles found', 'article' ),
		'not_found_in_trash' => _x( 'No articles found in Trash', 'article' ),
		'parent_item_colon'  => _x( 'Parent article info:', 'article' ),
		'menu_name'          => _x( 'Articles', 'article' ),
	);

	$args = array(
		'labels'              => $labels,
		'hierarchical'        => true,
		'description'         => 'Articles',
		'supports'            => array(
			'title',
			'editor',
			'author',
			'thumbnail',
			'trackbacks',
			'custom-fields',
			'comments',
			'revisions',
			'page-attributes'
		),
		'taxonomies'          => array( 'post_tag' ),
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'menu_position'       => 5,
		'menu_icon'           => 'dashicons-welcome-write-blog',
		'show_in_nav_menus'   => true,
		'publicly_queryable'  => true,
		'exclude_from_search' => false,
		'has_archive'         => true,
		'query_var'           => true,
		'can_export'          => true,
		'rewrite'             => true,
		'capability_type'     => 'post'
	);

	register_post_type( 'article', $args );
}

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

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

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

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

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

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

php 注册自定义帖子类型