VPS参考测评推荐
专注分享VPS主机优惠信息
衡天云优惠活动
华纳云最新优惠促销活动
jtti最新优惠促销活动

在wordpress主题中添加自定义文章类型register_post_type和分类教程(WordPress文章类型)。

locvps
主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情!
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作

WordPress作为一个简单实用的CMS系统,由于其强大的功能和易于开发,受到了很多站长的青睐。最实用的是支持自定义文章类型和分类,非常好用。这篇文章博主会给大家简单讲解一下如何在我们的主题中添加自定义文章类型register_post_type和类别register_taxonomy。

在wordpress主题中添加自定义文章类型register_post_type和分类教程(WordPress文章类型)。-主机参考WordPress 1。添加自定义文章类型。

/*注册自定义帖子类型*/ add_action( 'init ',' create _ products _ Post _ Type ');//add portfolio function create _ products _ post _ type(){ $ labels = array(' name ' = & gt;_ _ ('product ',' wpgp '),' singular _ name' = >: _ _ ('product ',' wpgp '),' add _ new' = >: _ _ ('add ',' wpgp '),' add _ new _ item' = >: _ _ ('new product ',' wpgp '),' edit _ item' = >: _ _ ('edit product ',' wpgp '),' new -item ' = >;_ _('新产品',' WPGP '),' view _ item ' = & gt_ _('查看产品',' WPGP '),' search _ items ' = & gt_ _('搜索产品',' wpgp '),' not _ found ' = >;_ _('找不到产品',' wpgp '),' not _ found _ in _ trash' = > _ _('垃圾桶内找不到产品',' wpgp '),' parent _ item _ colon ' = >;'',);$ args = array(' labels ' = & gt;$labels,' show _ ui ' = & gttrue,//是否在admin 'query _ var ' = & gttrue,' show _ in _ nav _ menus ' = & gtfalse,' public ' = & gttrue,//控制该类型如何对作者和读者可见。post ','层次' = & gtfalse,' menu _ icon ' = & gt' dashicons-format-gallery ',//使用字体图标,例如' dashicon S-chart -pie ' ' has _ archive ' = & gt;true,//启用post类型存档' rewrite ' = & gt数组(' slug ' = >;)products '),' supports ' = & gtarray( 'title ',' editor ',' thumbnail ',' extract ',' comments ',' custom-fields ',' page-attributes '),' can _ export ' = & gt真,);register_post_type( 'products ',$ args);}2.添加分类功能

add_action( 'init ',' register _ products _ taxonomy ');//为帖子类型“book”函数register _ products _ taxonomy(){//添加新的分类,使其具有层次性(像类别)$ labels = array(' name ' = & gt;_ _('产品分类',' wpgp '),' singular _ name' = >: _ _('产品分类',' wpgp '),' menu _ name' = >: _ _('产品分类',' wpgp '),' search _ items' = >: _ _ ('search ',' WPGP '),' all _ items ' = & gt_ _('所有产品分类',' wpgp '),' parent _ item' = >: _ _('本产品分类的上级分类'),' parent _ item _ colon' = >: _ _('本产品分类的上级分类:'),' edit _ item ' = & gt >;_ _('编辑产品分类',' wpgp '),' update _ item' = >: _ _('更新产品分类',' wpgp '),' add _ new _ item' = >: _ _('添加新的产品分类',' wpgp '),' new _ item _ name ' = >;_ _('新产品分类',' WPGP '),);$ args = array(' hierarchical ' = & gt;true,' labels ' = & gt$labels,' show _ ui ' = & gttrue,' show _ in _ menu ' = & gttrue,' show _ in _ nav _ menus ' = & gttrue,' query _ var ' = & gttrue,' has _ archive ' = & gtfalse,' show _ admin _ column ' = & gt真,'重写' = & gt数组(' slug ' = & gt产品’),);register_taxonomy( 'product ',' products ',$ args);}3.在后台添加自定义文章排序的功能。

//管理页面产品orderbyadd_filter( 'parse_query ',' sort _ products _ by _ date ');函数sort _ products _ by _ date(){ global $ page now;if(is _ admin()& amp;& amp$ pagenow = = ' edit.php ' & amp& amp!空($ _ GET & # 091post _ type ']= = ' products ')& amp;& amp!isset($ _ GET & # 091;post _ status '])& amp;& amp!isset($ _ GET & # 091;order by ']){ WP _ redirect(admin _ URL(' edit . PHP?产品和服务。orderby =日期和时间。order = desc '));退出;}}

这几篇文章你可能也喜欢:

本文由主机参考刊发,转载请注明:在wordpress主题中添加自定义文章类型register_post_type和分类教程(WordPress文章类型)。 https://zhujicankao.com/88867.html

【腾讯云】领8888元采购礼包,抢爆款云服务器 每月 9元起,个人开发者加享折上折!
打赏
转载请注明原文链接:主机参考 » 在wordpress主题中添加自定义文章类型register_post_type和分类教程(WordPress文章类型)。
主机参考仅做资料收集,不对商家任何信息及交易做信用担保,购买前请注意风险,有交易纠纷请自行解决!请查阅:特别声明

评论 抢沙发

评论前必须登录!