What’s a good practise in registering a custom post type? I have read the documentation and even tried searching the forums, but I’m afraid the information falls a little short (at least for me). Don’t misunderstand me, I love Sage.
Where can I create a CPT?
And also, template wise, does this 1 year old thread still count as a solution?
slobich: Thanks for the fast answer. Will look into the URLs you posted. So to get this straight: your least favorite method (and the oldest method) would be to register custom post types in functions.php in Sage root?
I used to use my sage theme for registering the post-types, and its fine to do so, but it makes making changes to them difficult, and limits you to using one theme or else edit/duplicating for a second theme or a second site.
first of i would not register the CPT in functions.php, as you can see that file just calls other files from lib so i would either register in extras.php or make a new file like cpt.php and add it there. that is if you want to go with that method of registering CPT’s in a theme.
as for your question about the method. it’s not a huge deal. nothing will go terribly wrong if you decide to do it like that. but adding a plugin will maybe make things a bit easier. let’s say you’re doing some development and you have an issue on an archive page of a certain CPT. and you decide to rule out issues with your theme and decide to activate a different theme just to see if the issue is is still present. well if your CPT is registered in your theme you can’t see it if your theme is not active. or if your client decides to make a new web site/new theme latter. because your CPT is tied in with your theme they’ll have to move the CPT code from your theme to their new theme. but again this is not a huge deal. just a bit cleaner as @evanfuture pointed out.
one more note. sometimes i make a plugin for that and add it to mu-plugins. this is just so no one can accidentally deactivate it. but again that can cause issues latter on for the client if they decide to remove it by themselves if they don’t know how to use ftp or don’t know what mp-plugins are. so i tend to decide that on a case to case basis.
i suggest you read the article from Justin Tadlock i posted in my first post. he does say at the beginning of the post that his article is mainly focused on public themes but i think a lot of it can be applied to custom theme work as well.
Thanks for some well thought and weighted posts, slobich and evanfuture. I’m kind of new to Sage, so I’m just learning the basics for now, just to get the hang of how the template system works, etc. So for starters I will only make a cpt.php and include it in the array in functions.php. But later, when I get it more under my skin, I will make a plugin out of it. Of cource a MU one.
Hey, I know the rules I’m just testing/playing locally to get to know Sage, nothing else. Nothing will be released like this. I appreciate your passion for good coding.