wordpress 添加自定义文章类型

目标:

1、包括列表、添加、分类、标签等功能

function products_post_type() {
	$labels = array(
		'name' => '产品', // 自定义文章类型的名称
		'singular_name' => '产品', // 自定义文章类型的单数名称
		'menu_name' => '产品', // 后台菜单中显示的名称
		'add_new' => '添加', // 添加新文章的按钮文本
		'add_new_item' => '添加', // 添加新文章页面的标题
		'edit' => '编辑', // 编辑按钮的文本
		'edit_item' => '编辑', // 编辑文章页面的标题
		'new_item' => '编辑', // 添加新文章页面的标题
		'view' => '查看', // 查看按钮的文本
		'view_item' => '查看标题', // 查看文章页面的标题
		'search_items' => '搜索产品', // 搜索文章的文本
		'not_found' => '没找到产品', // 没有找到文章时的文本
		'not_found_in_trash' => '没找到产品', // 回收站中没有找到文章时的文本
		'parent' => '父级产品' // 父级文章的文本(如果有)
	);
	$args = array(
		'labels' => $labels,
		'public' => true, // 是否公开可见
		'publicly_queryable' => true, // 是否可以通过公共查询访问
		'show_ui' => true, // 是否显示在管理界面
		'show_in_menu' => true, // 是否显示在后台菜单中
		'query_var' => true, // 是否可用于URL查询
		'rewrite' => array('slug' => 'products-post'), // 重写规则,定义文章的URL
		'capability_type' => 'post', // 用户角色访问权限
		'has_archive' => true, // 是否具有存档页面
		'hierarchical' => false, // 是否具有层次结构
		'menu_position' => 5, // 在后台菜单中的位置
		'supports' => array('title', 'editor', 'thumbnail') // 文章支持的功能(标题,编辑器,缩略图等)
	);
	register_post_type('products_post', $args); // 注册自定义文章类型

	$taxonomy_labels = array(
		'name' => 'Products Categories',
		'singular_name' => 'Products Category',
		'menu_name' => 'Products Categories',
		'all_items' => 'All Categories',
		'edit_item' => 'Edit Category',
		'view_item' => 'View Category',
		'update_item' => 'Update Category',
		'add_new_item' => 'Add New Category',
		'new_item_name' => 'New Category Name',
		'parent_item' => 'Parent Category',
		'parent_item_colon' => 'Parent Category:',
		'search_items' => 'Search Categories',
		'popular_items' => 'Popular Categories',
		'separate_items_with_commas' => 'Separate categories with commas',
		'add_or_remove_items' => 'Add or remove categories',
		'choose_from_most_used' => 'Choose from the most used categories',
		'not_found' => 'No categories found'
	);
	$taxonomy_args = array(
		'labels' => $taxonomy_labels,
		'hierarchical' => true,
		'public' => true,
		'rewrite' => array('slug' => 'products-category')
	);
	register_taxonomy('products_category', 'products_post', $taxonomy_args);

	$tag_labels = array(
		'name' => 'Products Tags',
		'singular_name' => 'Products Tag',
		'menu_name' => 'Products Tags',
		'search_items' => 'Search Tags',
		'popular_items' => 'Popular Tags',
		'all_items' => 'All Tags',
		'edit_item' => 'Edit Tag',
		'update_item' => 'Update Tag',
		'add_new_item' => 'Add New Tag',
		'new_item_name' => 'New Tag Name',
		'not_found' => 'No tags found'
	);
	$tag_args = array(
		'labels' => $tag_labels,
		'public' => true,
		'hierarchical' => false,
		'rewrite' => array('slug' => 'products-tag')
	);
	register_taxonomy('products_tag', 'products_post', $tag_args);
}
add_action('init', 'products_post_type');
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值