background preloader

WordPress, les Custom Post Types par l'Exemple

WordPress, les Custom Post Types par l'Exemple
Les Custom Post Types, qui pourrait se traduire par Types de Billet Personnalisé, sont une notion qui a été introduite avec la version 3 de WordPress. Il s’agit de créer une interface de gestion et de présentation de votre contenu qui corresponde à 100% de vos besoins. La présentation d’une équipe peut se reposer, par exemple, sur un Custom Post Type, vous permettant de gérer de façon centralisée cette page. Mais avant de parler de type de contenu personnalisé, il faut savoir que WordPress se base sur 5 formats de contenus majeurs : Les billets – PostLes pages – PageLes médias – AttachmentLes révisions d’articles – Article revisionLes menus de navigation – Nav menus Pour connaitre la liste complète, n’hésitez pas à lire la page du codex. Tous les types de contenu sont stockés dans la table wp_posts, au nom de colonnes commençant par post_type. Voila pour la présentation très généraliste des types de contenu sous WordPress. Avant d’aller plus loin, voici comment ce tutoriel ce décompose :

Customizing WordPress Using Custom Post Types One of WordPress’ greatest features is its ability for customization. There are many sites out there that could benefit greatly from these features. I’ve seen sites that sell cars and houses to simple music sites that could benefit from one specific customization function within WordPress, the register_post_type. The register_post_type function, as its name suggests allow the user (or theme) to add a new post type such as car, house or album. Once this post type has been registered, the user can then start adding functionality to WordPress that is unique to the post type. Adding a custom post type For this example I’m going to stick with the Car sales example. A quick overview of a car tells us that there are certain characteristic that can be assigned to cars. Number of doorsBody type, e.g. These attributes or characteristics could the custom taxonomies we will be assigning to our custom post type. To actually add this to an existing theme you’ll need to hook into the init action.

Using SuperCPT to Create Custom Post Types, Taxonomies and Meta Boxes With the release of version 3.0, WordPress introduced custom post types and updated custom taxonomies which were introduced in v2.8. Since then, WordPress users and developers are able to create their own post types and taxonomies. People are no longer chained to the dull "posts" and "pages" with the boring "categories" and "tags". Yes, using custom post types, custom taxonomies and custom meta boxes are cool. The Hassle of Creating Custom Post Types and Taxonomies I find it hard and boring to create custom post types and taxonomies with the register_post_type() and register_taxonomy() functions. Even as a developer, it's painful to do this with every single post type and taxonomy I have to create - I can't imagine how hard it is for novice WordPress users. Don't get me wrong, you still can or have to do them with SuperCPT, too - but SuperCPT embraces the DRY (Don't Repeat Yourself) principle and eases up the process. Using SuperCPT, the All-in-One Solution The Screencast Conclusion

How to Add Custom Meta Boxes in WordPress Posts and Post Types Just last week, we showed you how to add custom meta fields to custom taxonomies in WordPress. That article brought our attention to another important topic of how to add custom meta boxes in WordPress posts and post types. We wrote about a plugin method of adding meta boxes and custom write panels using More Fields plugin, but the development of that plugin has stopped. We had linked to some good tutorials that showed how to do add custom meta boxes in WordPress from our Custom Fields 101 article however all those are no longer available. Note: This tutorial is for designers and developers. Because the goal of this article is to show you how to create reusable meta boxes in WordPress, we will be utilizing a Custom Metaboxes and Fields for WordPress class (CMB) by Andrew Norcross (@norcross), Jared Atchison (@jaredatch), and Bill Erickson (@billerickson). First thing you need to do is download the CMB class. Now let’s create a blank PHP file, and call it cmb-wp.php.