Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHarry Heathcock
8,407 PointsNo project downloads for custom post template creation in Wordpress
The files that the instructor uses in the video when creating a custom post type template are not available to download, so I copied them word for word, space for space and did everything he did, but it did not work for me. Is there something in the files that I'm missing? And why aren't they available for download when he says they are?
2 Answers
Patrick Bowles
14,993 PointsI also copied the text from the video. I have the "Art Page" template and the main art page working, but the art piece titles (e.g. "Example 1", "Example 2", etc) aren't clickable to the single art page. I triple checked the code, so I don't think it's a transcription error. Here is my code:
<?php
/**
* Template Name: Art Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php comments_template(); ?>
<?php endwhile; ?>
<?php
$args = array(
'post_type' => 'art',
'orderby' => 'title',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', 'art' ); ?>
<?php endwhile; endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
/**
* Template for displaying art custom post type entries
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-meta">
<p>Price: $<?php the_field('price'); ?></p>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<p><img src="<?php the_field('image'); ?>" alt="Example image of <?php the_title(); ?>"></p>
<p><?php the_field('description'); ?></p>
</div><!-- .entry-content -->
</article><!-- #post -->
<?php
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php get_template_part( 'content', 'art' ); ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Jacob Mishkin
23,118 Pointsyeah, I just saw, and there you're right, there are no project files to be found. That's a bummer, but you can use this handy site to generate CPT's here generatewp it's pretty handy for things like this. Remember to put this in your functions.php or inc folder, depending on what theme you are using. If you have any questions please ask.