VPS参考、测评、推荐
分享你关注的VPS主机优惠信息

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

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

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

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

/*自定义帖子类型*/ add_action( ‘init ‘,’ create _ products _ Post _ Type ‘);//add portfolio 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,’ ‘ = & 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(){ $ 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 ‘]){ _ redirect(admin _ URL(‘ edit . PHP?产品和服务。orderby =日期和时间。order = desc ‘));退出;}}

:在wordpress主题中添加自定义文章类型register_post_type和分类(WordPress文章类型)。 ://vps.caogenba.com.com/88867.html

赞(0) 打赏
未经允许不得转载:草根吧VPS_最新VPS信息参考 » 在wordpress主题中添加自定义文章类型register_post_type和分类教程(WordPress文章类型)。
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址