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的书签

热门文章

EWS(Exchange Service)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议) 最近公司要求和exchange服务对接,所以稍微研究了一下官方文档,做出以下总结,欢迎大家补充。先...EWS(ExchangeService)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议) 作者:Pastore Antonio
1593 浏览量
Sql Server 部署SSIS包完成远程数据传输 本篇介绍如何使用SSIS和作业完成自动更新目标数据任务。**温馨提示:如需转载本文,请注明...SqlServer部署SSIS包完成远程数据传输 作者:Pastore Antonio
1588 浏览量
SQL Server AG集群启动不起来的临时自救大招 背景前晚一朋友遇到AG集群发生来回切换不稳定的情况,情急之下,朋友在命令行使用命令重启WSFC集群...SQLServerAG集群启动不起来的临时自救大招 作者:Pastore Antonio
1578 浏览量
SharePoint2010升级到SharePoint2013操作手册 SharePoint2010升级到SharePoint2013操作手册目录第一章...SharePoint2010升级到SharePoint2013操作手册 作者:Pastore Antonio
1568 浏览量
C# DataTable 某一列求和 列为数字类型doubletotal=Convert.ToDouble(datatable.Com...C#DataTable某一列求和 作者:Pastore Antonio
1560 浏览量