Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6470609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:07:51+00:00 2026-05-25T06:07:51+00:00

I know how to create a custom template for a specific page. However I

  • 0

I know how to create a custom template for a specific page. However I would like to create a template for a specific custom post type. Is that possible and if true how can I do that?

If I create a new template it will show in admin only when I’m adding a page, but when I’m adding a new post type I don’t have the option to select a certain template.

Problem resolved:

/* 
Show the list of available custom templates templates in the Custom Post Type admin section
*/

/**
 * Post_type
 */
define( 'MY_THEME_POST_TYPE', 'cases' );
/**
 * Load the page template for any post object
 * having the appropriate meta key set.
 */
add_action( 'template_redirect', 'mytheme_template_redirect' );
function mytheme_template_redirect() {
    global $wp_query;
    $id = (int) $wp_query->get_queried_object_id();
    $template = get_post_meta( $id, '_wp_page_template', true );
    if ( $template && 'default' !== $template ) {
        $file = STYLESHEETPATH . '/' . $template;
        if( is_file( $file ) ) {
            require_once $file;
            exit;
        }
    }

}
/**
 * Process the Meta Box
 * @todo Permissions check.
 * @todo Filter input.
 * @todo Nonces.
 */
add_action( 'save_post', 'mytheme_process_resource_template' );
function mytheme_process_resource_template() {
    global $post;

    /* Sanitize $_POST array. */
    $clean_id = ( isset( $_POST['ID'] ) ) ? intval( $_POST['ID'] ) : 0;

    if ( !empty( $_POST['page_template'] ) && MY_THEME_POST_TYPE == $post->post_type ) {
        $page_templates = get_page_templates();
        if ( 'default' != $page_template && !in_array( $_POST['page_template'], $page_templates ) ) {
            if ( $wp_error )
                return new WP_Error('invalid_page_template', __('The page template is invalid.'));
            else
                return 0;
        }
        update_post_meta( $clean_id, '_wp_page_template',  $_POST['page_template'] );
    }
}
/**
 * Registers the Meta Box
 * @uses mytheme_page_attributes_meta_box()
 */
add_action( 'admin_init', 'mytheme_register_meta_boxes', 10 );
function mytheme_register_meta_boxes()  {
    add_meta_box(
        'mytheme_post_type_template',
        'Template',
        'mytheme_page_attributes_meta_box',
        MY_THEME_POST_TYPE,
        'side',
        'low'
        );
}
/**
 * Creates the Meta Box
 */
function mytheme_page_attributes_meta_box() {
    global $post;
    $post_type_object = get_post_type_object($post->post_type);    
    if ( 0 != count( get_page_templates() ) ) {
        $template = get_post_meta( $post->ID, '_wp_page_template',  true );
        ?>
<p><strong><?php _e('Template') ?></strong></p>
<label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select name="page_template" id="page_template">
<option value='default'><?php _e('Default Template'); ?></option>
<?php page_template_dropdown( $template ); ?>
</select>
<?php
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:07:52+00:00Added an answer on May 25, 2026 at 6:07 am

    Create page that is called:

    single-{cpt-slug}.php e.g. single-product.php

    It will be used when showing a page of a custom post type. i.e. when someone goes to http://example.com/product/awesome-shoes/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I know how to create custom encrypted RSA keys, but how can
I know how to create a custom user control in WPF but how can
I want to know if i can create a custom google maps application,on which
I would like to know How to create a fps-game with SDL lib? Are
I have a wordpress blog. I made a custom page-template that allows users to
I want to know something about this article In order to create custom post
i kinda know how to create a Custom Web Part. But now i need
I am trying to create a custom Application template. I tried to learn, How
Using Visual Studio 2008, I need to create a custom web form that when
Id' like to know how to write a constructor for a custom class (a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.