WordPress Custom Post Type Code
// custom post type code from functions.php
// I created a custom post type 'code-snippet'
// with taxonomy 'technology'
add_action( 'init', 'create_code_snippets' );
function create_code_snippets() {
$labels = array(
'name' => _x('Code Snippets', 'post type general name'),
'singular_name' => _x('Code Snippet', 'post type singular name'),
'add_new' => _x('Add New', 'Code Snippet'),
'add_new_item' => __('Add New Code Snippet'),
'edit_item' => __('Edit Code Snippet'),
'new_item' => __('New Code Snippet'),
'view_item' => __('View Code Snippet'),
'search_items' => __('Search Code Snippets'),
'not_found' => __('No Code Snippets found'),
'not_found_in_trash' => __('No Code Snippets found in Trash'),
'parent_item_colon' => ''
);
$supports = array(
'title',
'editor',
'author',
'custom-fields',
'revisions',
'excerpt',
'thumbnail',
'comments',
'trackbacks'
);
// wordpress function to register post type
// http://codex.wordpress.org/Function_Reference/register_post_type
register_post_type( 'code-snippet',
array(
'labels' => $labels,
'public' => true,
'menu_position' => 5,
'supports' => $supports
)
);
}
// to build taxonomy 'technology' for custom post type 'code-snippet'
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy(
'technology',
'code-snippet',
array(
'hierarchical' => false,
'label' => 'Technology',
'query_var' => true,
'rewrite' => true
)
);
}
Use the following code in your template page to create a custom loop that displays code snippets.
query_posts("post_type=code-snippet");
I hope this will help.
Thanks



Saqib, Would you happen to have a example/demo to take a peek at? Thanks for sharing.
@David the code snippets section in this website is an example for this custom post type code.
HEllo, I am creating a gallery of products (shoes, clothes, t-shirts, etc…) I was wondering how can I reduce coding by implementing an arrays in registering and defining the products since all will have the same properties via the main categories. I think it is a waste of time to individually register and define products one by one.
Thanks for your comment @Toure, I think it would be better to define just one custom post type for products and classify different products types using custom taxonomies. Google about custom taxonomies and you will know what I am saying.
I tried, but I found redundant to do that since all of the products have the same taxonomies (model for men-women-kids, size, brand). i found it easy and cleaner to use the built-in category et only use custom post type to separate different kind of products like shoes, dresses, hoodies, etc…
I hope there might better ways of doing it without cluttering the functions.php file.
It even easier to query the built-in categories.
Any body, please guide me in the right direction.
Thanks
@Tour. can you send me your function.php so that I can have a look on what exactly you are doing ?