I created a custom post type called portfolio. I also created a file called single-portfolio.php to display the portfolio content.
When creating a portfolio post, the template I want to use doesn't show up in the dropdown list under the Attributes section. In fact, the dropdown list doesn't show up at all until I create my first portfolio post, at which point, the dropdown list is populated with two items:
-(no parent)
-[Title of the first Portfolio post]
Here's what's in functions.php
add_action('init', 'create_portfolio');
function create_portfolio() {
$labels = array(
'name' => _x('My Portfolio', 'post type general name'),
'singular_name' => _x('Portfolio Item', 'post type singular name'),
'add_new' => _x('Add New', 'portfolio item'),
'add_new_item' => __('Add New Portfolio Item'),
'edit_item' => __('Edit Portfolio Item'),
'new_item' => __('New Portfolio Item'),
'view_item' => __('View Portfolio Item'),
'search_items' => __('Search Portfolio'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$portfolio_args = array(
'labels' => $labels,
'label' => __('Portfolio'),
'singular_label' => __('Portfolio'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => true,
'has_archive' => true,
'rewrite' => array("slug" => "portfolio"),
'can_export' => true,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'page-attributes')
);
register_post_type('portfolio',$portfolio_args);
}
And single-portfolio.php
<?php
/*
Template Name: Single Portfolio
*/
?>
<?php get_header(); ?>
<div id="main">
<?php $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 10));
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$custom = get_post_custom($post->ID);
$screenshot_url = $custom["screenshot_url"][0];
$website_url = $custom["website_url"][0];
$date_completed = $custom["date_completed"][0];
?>
<div id="portfolio-item">
<h1><?php the_title(); ?></h1>
<?php echo 'Completed:'; $custom["year_completed"][0]; ?>
<a href="<?=$website_url?>"><?php the_post_thumbnail(); ?> </a>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
</div><!--MAIN-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>