Forums

Multiple Custom Content Types - Same page template (4 posts)

  1. tpeterson
    Member
    Posted 1 year ago #

    Hi all,
    I've got 3 different custom content types in my WordPress 3.1 site.
    For ease of management moving forward, I'd like to use the same page_type template for each custom content type.

    Obviously, I can create a post type specific template for each custom content type using the single-{post_type}.php

    But, what if I wanted to use the same template for each post type, how would I do that?

    Thanks!
    Troy

  2. Chip Bennett
    Member
    Posted 1 year ago #

    According to the Codex:

    Single CPT template file: single-{posttype}.php
    Archive/Index CPT template file: archive-{posttype}.php

    So, if you've named your CPT "prefix_foobar":

    Single CPT template file: single-prefix_foobar.php
    Archive/Index CPT template file: archive-prefix_foobar.php

  3. tpeterson
    Member
    Posted 1 year ago #

    Hi Chip,

    Yes, on a per-cpt basis, I can create the template file for them.
    But, if I want to use the same template for multiple cpt's, that's what I'm looking for...

    So cpt's prefix_foobar1 & prefix_foobar2 both use single-prefix_foobar3.php as the template.

    I hope that makes more sense.

    Thanks!
    Troy

  4. Chip Bennett
    Member
    Posted 1 year ago #

    The easiest thing to do might be to create "prefix_foobar.php" which contains your desired markup.

    Then, for each of your CPTs, create the appropriate template file, in which you simply call:

    get_template_part( 'prefix_foobar' );

    So, you'd still need to create each of the CPT template files, but you only have to maintain one single template file, that gets called by each one.

Topic Closed

This topic has been closed to new replies.

About this Topic