WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type Category Template (2 posts)

  1. swcomm
    Member
    Posted 2 years ago #

    I want to use a completely different single.php template (which uses a different header, footer and css file) for one category within a custom post type. This custom post type already has a single.php template separate from the rest of the site. I tried a category template, but I think because the posts in this category are also included in other categories, I'm not getting the results I want. Taxonomy doesn't really seem to fit the situation, so I'm not sure how to do this. Advice? Thanks.

  2. vtxyzzy
    Member
    Posted 2 years ago #

    You might be able to use this approach.

    You did not give the custom post type name, so assume it is 'custom' and your special category is 'special' with id = 6.

    • Rename single-custom.php to single-custom-default.php.
    • Create a new single-custom-special.php template for the custom posts in the special category.
    • Create a new single-custom.php template and use code similar to the following.
    <?php
    // single-custom.php is now in single-custom-default.php
    // We want to use single-custom-special for category 'special' (id = 6).
    $post = $wp_query->post;
    if ( in_category(array(6) )) {
      include(TEMPLATEPATH . '/single-custom-special.php'); }
    else {
      include(TEMPLATEPATH . '/single-custom-default.php');
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic