Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Currently wordpress "pages" can have a particular page template associated with it. Can this feature also be available for custom post types ?

share|improve this question

1 Answer 1

You can certainly set up a page template for custom post types. Give this a whirl:

<?php
/*
Template Name: Your template name
*/

// Get header
get_header(); ?>

<div id="primary">
<?php // Query post type
$the_query = new WP_Query( array( 'post_type' => 'cpt_name', 'posts_per_page' => -1 ) ); 
if ( $the_query->have_posts() ) : ?>

<?php // Begin loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<section>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</section>

<?php endwhile; ?>

<?php // Reset
wp_reset_postdata(); ?>

<?php else:  ?>
<p><?php _e( 'Please add some content.' ); ?></p>
<?php endif; // End loop and primary ?>
</div>

<?php get_footer(); ?>
share|improve this answer
    
Ah, I see what you mean. I figured that the post-type needs to be set to "hierarchical" –  Prakash Raman Mar 26 at 19:27
    
Cool. You might also want to check this out: codex.wordpress.org/Post_Types#Template_Files –  Squideyes Mar 26 at 19:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.