admin管理员组文章数量:1430644
I'm creating my first Wordpress theme and I learned about custom post types. They sounded great for different reasons and I really wanted to implement them. But I read somewhere that when the user of the theme changes to another theme that doesn't support that post type, they'll literally lose the ability to see all their custom posts.
I don't want this to happen, so I'm thinking of other approaches like
- Telling the users to create categories and loop the to get posts from the category
- Creating custom taxonomies.
At this point, I need your help because you have experience creating these classes of post types. What could I do and why?
I'm creating my first Wordpress theme and I learned about custom post types. They sounded great for different reasons and I really wanted to implement them. But I read somewhere that when the user of the theme changes to another theme that doesn't support that post type, they'll literally lose the ability to see all their custom posts.
I don't want this to happen, so I'm thinking of other approaches like
- Telling the users to create categories and loop the to get posts from the category
- Creating custom taxonomies.
At this point, I need your help because you have experience creating these classes of post types. What could I do and why?
Share Improve this question asked Apr 25, 2019 at 13:42 Victor OfoegbuVictor Ofoegbu 1115 bronze badges 4- When you intend to extend the functionality (e.g. by adding new post type) you should create a plugin. This way, additional functionality will be available as long as the plugin is active, regardless of the selected theme. – nmr Commented Apr 25, 2019 at 14:04
- Thank you friend. So in essence, I should create plugins for every theme I make? – Victor Ofoegbu Commented Apr 25, 2019 at 14:10
- 1 Only if you need to add functionality which would otherwise break if you changed theme. – Alexander Holsgrove Commented Apr 25, 2019 at 14:22
- 1 If something is not related only to your theme, you should think about moving it to the plugin. – nmr Commented Apr 25, 2019 at 14:27
2 Answers
Reset to default 1You've highlighted the issue of creating custom post types in a theme rather than in a plugin. If the user changes to a new theme then you cannot rely on any functionality in the theme you have created.
Themes can add functionality, but in general should be concerned with the presentation of your site
Plugins will add functionality
Hence this is where I suggest you add the register_post_type code. The Registering Custom Post Types documentation recommends this approach as well, so have a good read through that for more detail.
What you've heard is correct. If you have developed specialized views of your custom post type (archive pages, single pages, categories, or setup custom queries for your post type ) and a user changes themes all those views are lost.
It's true, as has been mentioned, that the Custom Post Type should be created in a plugin, but the presentation of that cpt is created in the theme.
The real question, is once you've put time and energy into a creating a look and feel of your site, why would you let a user change the theme? You have created a design: stay with it. The reality is that more than just the custom post presentation will be lost if you change themes. The presentation of your blog goes too. Your colors, your fonts, your layout all are gone and back to what ever the new themes settings are.
Now when the theme is changed, your pages, posts, AND cpt will still be displayed (because you created the CPT in a plugin) but they will be presented in a fashion that the new theme designer created. Since that designer was not thinking about your cpt wordpress will just treat your posts as default blog posts.
Think about it though, if you give a user the ability to change themes, then they likely can change your plugins too.
TLDR: Choose a theme and stick with it(don't change it unless there is a good reason). Create your CPT. Do it in a plugin.
本文标签: Should I create Custom Page Types
版权声明:本文标题:Should I create Custom Page Types? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745553444a2663049.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论