1

I've managed to figure out how to use Custom Post Type templates now and they are great. I do however want to know if there is not a way to use a current template I have developed for other pages.

What I have is a page-three-column.php file using conditional checks to see which page it is on and then displaying the relevant content as it needs to.

Rather than copy this html over to the single-product.php template, I want to be able to use the page-three-column.php again as it has all the structure already in place and I wont need to duplicate html and compare it.

Is there a way to "force" wordpress to use a specific template rather than the Custom Post Type template?

I've read through the Codex to see if there is a conditional check one could use and thought that is_single( 'product' ) might work.

Clearly the custom post type template was built to display the content as it is intended but if there is another way, I would appreciate the help?

Many thanks.

1

2 Answers 2

1

You may not completely get out without using a template file. I might be wrong!!. But, by using get_template_part in your single-product.php you will be able to use page-three-column.php file.

So in your single-product.php something like this should do.

<?php get_template_part( 'page-three-column.php' ); ?>

You may refer to the Codex here.

2
  • You don't need to add any templates for CPT's, either single or archive if you don't want custom template files. Commented Jan 21, 2014 at 10:17
  • @BradDalton I agree it is not a must. I was suggesting that you need a template to display information. You need a different template if your purpose is different!
    – sri
    Commented Jan 21, 2014 at 10:23
0

You can use code like this

function portfolio_archive_page_template(){

return locate_template( 'archive-portfolio.php', true );

}

add_filter( 'archive_template', 'portfolio_archive_page_template' );

You can use a conditional for a page template:

is_page_template('your-page-template.php)

For single.php and archive-cpt.php templates, you name the file using the name of the CPT.

single.cpt.php or archive.cpt.php renaming cpt with the name of your cpt.

This page on the Codex pretty much explains it http://codex.wordpress.org/Post_Type_Templates

Along with this http://codex.wordpress.org/Post_Types#Custom_Post_Type_Templates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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