Custom Post Types on

In February, Smashing WordPress published a post offering advice to WordPress newbies, and one piece of advice that’s really stuck with me was “Write. You learn best when you are explaining what you do to other people.” I’ve learned that I really do gain an even better grasp of material when I try to explain it to others, though I sometimes don’t give myself enough credit to think I have anything worth teaching.

For once, however, in completing the site, I did a number of things I’d never done before, things I’m quite proud of. For one, I created my very own custom post type, which you can see in action with some test content on the Pitch page on my own server.

During the design process, I thought it would be a good idea to include some of the pitches that have been successful at fastpitch! in the past. I thought examples of good pitch decks would help to convince people they could and should sign up to pitch. My supervisors loved this idea, and then I realized I needed a way to implement it so that the person maintaining the site–not a tech person, I should add–could comfortably maintain that section in the future.

I decided the best solution was to create a custom post type and write a loop calling the most recent posts of that type. I used this page of the Codex to work out exactly how to create the post type, and I added this code to my functions.php file:

add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'pitchdeck',
			'labels' => array(
				'name' => __( 'Pitch' ),
				'singular_name' => __( 'Pitches' )
			'description' => 'The pitches to be shown on Pitch 101',
			'supports' => array(
			'public' => true,
			'has_archive' => true,
add_theme_support( 'post-thumbnails', array('pitchdeck') );

With that in place, I checked out my dashboard just to make sure the post type was showing up. It was, so I moved on to writing the loop in the Pitch page template. I knew I only wanted the images to appear, and I wanted them to be links that led to the actual pitch decks. I decided the best way to do that would be to use the featured image as the content of each post called by the loop, with the title of the post as the title of the link. I used the URL of the pitch deck as the content of the post, and I used get_the_content() to call the text of the post (the URL) in the a tag surrounding each featured image.
If that sounded a bit confusing, take a look at the code:

 'pitchdeck', 'posts_per_page' => 4 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>

It turned out perfectly, giving the webmaster an incredibly simple way to add new pitches to that part of the site in the future.

Share your thoughts