主机评测网,专注vps、独立服务器等主机评测
最专业的主机评测网站

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

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

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://vps.caogenba.com.com/88867.html

赞(0) 打赏
未经允许不得转载:主机测评 » 在wordpress主题中添加自定义文章类型register_post_type和分类教程(WordPress文章类型)。

评论 抢沙发

登录

找回密码

注册