- /***Custom Post Type : Portfolio***/
- add_action('init', 'portfolio');
- function portfolio()
- {
- $labels = array(
- 'name' => _x('Portfolios', 'post type general name'),
- 'singular_name' => _x('Portfolio', 'post type singular name'),
- 'add_new' => _x('Add New', 'portfolio'),
- 'add_new_item' => __('Add New Portfolio'),
- 'edit_item' => __('Edit Portfolio'),
- 'new_item' => __('New Portfolio'),
- 'view_item' => __('View Portfolio'),
- 'search_items' => __('Search Portfolios'),
- 'not_found' => __('No portfolios found'),
- 'not_found_in_trash' => __('No portfolios found in Trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'menu_position' => 4,
- 'supports' => array('title','editor','thumbnail','custom-fields')
- );
- register_post_type('portfolio',$args);
- }
- //hook into the init action and call create_book_taxonomies when it fires
- add_action( 'init', 'create_portfolio_taxonomies', 0 );
- //create two taxonomies, genres and writers for the post type "book"
- function create_portfolio_taxonomies()
- {
- // Add new taxonomy, make it hierarchical (like categories)
- $labels = array(
- 'name' => _x( 'Projects', 'taxonomy general name' ),
- 'singular_name' => _x( 'Project', 'taxonomy singular name' ),
- 'search_items' => __( 'Search Projects' ),
- 'all_items' => __( 'All Projects' ),
- 'parent_item' => __( 'Parent Project' ),
- 'parent_item_colon' => __( 'Parent Project:' ),
- 'edit_item' => __( 'Edit Project' ),
- 'update_item' => __( 'Update Project' ),
- 'add_new_item' => __( 'Add New Project' ),
- 'new_item_name' => __( 'New Project Name' ),
- );
- register_taxonomy('genre',array('portfolio'), array(
- 'hierarchical' => true,
- 'labels' => $labels,
- 'show_ui' => true,
- 'query_var' => true,
- 'rewrite' => array('slug' => 'portfolio', 'with_front' => FALSE)
- ));
- }
- Then I'm using this code on my custom page template to show the posts.
- <?php
- $args=array(
- 'genre' => 'web',
- 'post_type' => 'portfolio',
- 'post_status' => 'publish',
- 'posts_per_page' => -1,
- 'caller_get_posts'=> 1
- );
- $my_query = null;
- $my_query = new WP_Query($args);
- if( $my_query->have_posts() ) {
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
- <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
- <p><?php the_content(); ?></p>
- <?php
- endwhile;
- }
- wp_reset_query(); // Restore global post data stomped by the_post().
- ?>