newssnippetsimagesfav

Blog > Scripts > PHP Scripts > Wordpress > Custom post types with custom taxonomies

Last articles

  • Google Plus Opens first API developer system
    Google Plus Opens first API developer system
  • Seagate GoFlex – the biggest external HDD
    Seagate GoFlex – the biggest external HDD
  • Baidu to have a new mobile OS
    Baidu to have a new mobile OS
  • How to Download YouTube Songs Onto iTunes, mp3
    How to Download YouTube Songs Onto iTunes, mp3
  • How to Download YouTube Songs
    How to Download YouTube Songs
  • Google will close 10 services
    Google will close 10 services
  • Deep Sea Wallpapers
    Deep Sea Wallpapers
  • 200 Abstract and Light Wallpapers
    200 Abstract and Light Wallpapers
  • How to test shortlinks
    How to test shortlinks
  • Huawei MediaPad – first 7 inch Android 3.2 tablet
    Huawei MediaPad – first 7 inch Android 3.2 tablet

Custom post types with custom taxonomies

0

Creating a custom post type associated with custom taxonomies. For those who don’t know, a taxonomy is a term (such as category, tag or anything else) related to posts. For more information about taxonomies, you should have a look at WordPress Codex.

In this example, we’ll create a custom post type named Albums, which belong to “Genres” (the custom categories) and have “Performer” as tags. This snippet has to be pasted in your functions.php file. With those 27 lines of codes, you can create a fully functional music albums archive. Ain’t that powerful?

function post_type_albums() {
	register_post_type(
                     'albums',
                     array('label' => __('Albums'),
                             'public' => true,
                             'show_ui' => true,
                             'supports' => array(
                                        'post-thumbnails',
                                        'excerpts',
                                        'trackbacks',
                                        'comments')
                                )
                      );
// Adding the Custom Taxonomy for Genres. Here we can create categories specific for this post type.
	register_taxonomy( 'genres', 'albums', array( 'hierarchical' => true, 'label' => __('Genres') ) );

// Adding the Custom Taxonomy for Performer. Here we can add tags specific for this post type.
        register_taxonomy( 'performer', 'albums',
		array(
                         'hierarchical' => false,
			 'label' => __('Performer'),
			 'query_var' => 'performer',
			 'rewrite' => array('slug' => 'performer' )
		)
	);
}
add_action('init', 'post_type_albums');

If you liked the article share it by Twitter, Facebook and Google +1.




    WordPress 3.0: Query custom post types
    WordPress 3.0: Query custom post types
    How to create a custom post type in WordPress 3.0
    How to create a custom post type in WordPress 3.0
    Custom css for article
    Custom css for article
    WordPress 3.0: Custom author profiles
    WordPress 3.0: Custom author profiles
Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>