Logo

wordpress 添加自定义文章类型

photo

2024年04月17日

目标:

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');
所有附件
该文章没有附件.
本文为原创文章,请注意保留出处!

其实这个很简单,就是读取一个在用户目录里面的一个Bookmarks文件就好了。  先建立几个实...C#获取GoogleChrome的书签

热门文章

修复群晖Synology Drive client右键菜单缺失问题 本教程主要解决windows10右键菜单中没有SynologyDrive菜单的问题,整体思路是找到...修复群晖SynologyDriveclient右键菜单缺失问题 作者:Pastore Antonio
1826 浏览量
docker如何查看一个镜像内部的目录结构及其内部都有哪些文件 前言:有时候我们会在docker上下载一个镜像,或者是上传一个镜像到docker上,甚至有时候就是在...docker如何查看一个镜像内部的目录结构及其内部都有哪些文件 作者:Pastore Antonio
1808 浏览量
Adobe Acrobat Pro 激活 这里记录了一些AdobeAcrobat的激活教程和组件。浏览量:1,688 作者:Pastore Antonio
1535 浏览量
configure: error: Package requirements (oniguruma) were not met configure:error:Packagerequirements(oniguruma)...configure:error:Packagerequirements(oniguruma)werenotmet 作者:Pastore Antonio
1535 浏览量
追寻日出,找回自己 为什么我要去追寻日出?其实我是一个很懒的人,每次都起不来,直到有一次我在租房中睡到了大天亮,阳光照...追寻日出,找回自己 作者:Pastore Antonio
1515 浏览量