[Resolved] Custom post type template

Home Forums Support Custom post type template

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #245667

    Hi, I’m trying to create a template for a custom post type. I have created the file single-posttype.php. and I have noticed that it also uses the content.php. How can I create content-posttype.php and make single-posttype.php use it? I know this sounds complicated but I hope I made it clear.


    Lead Developer
    Lead Developer

    In your file, find:

    <?php get_template_part( 'content', 'single' ); ?>

    Now if your file is named content-posttype.php, replace it with:

    <?php get_template_part( 'content', 'posttype' ); ?>


    Awesome, thank you so much πŸ™‚

    Lead Developer
    Lead Developer

    Hello Tom!
    This information is very useful, thanks!

    I’m also working with custom post types and I want to edit not only the page template but also the archive page. So in my child theme I’ve created single-myCPT.php where I wrote
    <?php get_template_part( 'content', 'single-myCPT' ); ?>

    I’ve also created archive-myCPT.php but I don’t know how to reference my custom content replacing get_post_format().
    <?php get_template_part( 'content', get_post_format() ); ?>

    Hope I explained well…

    Thanks in advance!

    Lead Developer
    Lead Developer

    This line: get_template_part( 'content', 'single-myCPT' )

    Will look for a file like this: content-single-myCPT.php

    If you’re already using a custom single-myCPT.php file, you might as well copy the code inside content-single.php, and replace this with it:

    get_template_part( 'content', 'single' )

    get_template_part() is cool as it allows you to only change the loop – not the entire single.php file. In your case, it’s probably easier to keep everything in one file.


    Dear Tom,

    If i want to create a custom page, which page of your theme will be most usefull to get a basis ?

    content.php, page.php ??

    Lead Developer
    Lead Developer

    It depends on which areas you’re editing. page.php is likely the one you want to edit.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.