Voici mon premier plugin partagé pour WordPress. Je travaille beaucoup avec des catégories hiérarchisées, et cela peut être très utile de retrouver facilement l’ancêtre d’une catégorie.
Le plugin est basé sur une discussion dans le forum WordPress.org, j’ai réorganisé le code, et testé les différentes possibilités pour la fonction soit la plus facile à utiliser.
Comment ça marche ?
Très simplement, une fois activé, le plugin rajoute une fonction get_category_ancestor($thecat) que vous pouvez utiliser partout dans votre thème. Vous pouvez mettre en variable une id numérique ou un slug, et la fonction vous retournera le même type de données. Si la catégorie est au plus haut niveau de la hiérarchie, la fonction renvoie la même catégorie.
Il ne fonctionne qu’à partir de la 2.5
En le combinant avec les champs personnalisés, il peut devenir un outil pour gérer des pseudos types de contenus, en attendant la v 3.0
English description
This is my first released plugin for WordPress. I work a lot with deeply hierarchical categories, and it can be useful to easily find the ancestor. The plugin is based on a discussion on WordPress.org, I took the same idea, but reorganized the code, to make the function easy to use in « any configuration ».
How does it work ?
Really easy, once activated, the plugin adds a function get_category_ancestor($thecat) that you can use anywhere in the theme. You can provide either a numerical id or a slug as variable, and the return will be of the same type. If the category is already at the top level, the function returns the same category.
It requires at least 2.5
Combined with Custom Fields, it can become a tool to manage pseudo content types, while waitingfor 3.0
Download
Et si vous avez apprécié le plugin / If you appreciated the plugin …

























It is a very useful plugin. It would be nice, in a future version, to output the entire tree a category belongs to (for example: « You are in WordPress -> Development -> Plugins »), turning each sub-category in a link.