php - how to attach a page to a custom post type -


this has worked me in past, unsure why not working now.

i have created custom post type:

add_action('init', 'register_team');    function register_team(){         $args = array(             'label' => __('design team'),             'singular_label' => __('design team'),             'public' => true,             'show_ui' => true,             'capability_type' => 'post',             'hierarchical' => true,             'rewrite' => array("slug" => "design-team",'with_front' => true), // permalinks format             'supports' => array( 'title', 'editor', 'thumbnail' ),             'add_new' => __( 'add new member' ),             'add_new_item' => __( 'add new member' ),             'edit' => __( 'edit member' ),             'edit_item' => __( 'edit member' ),             'new_item' => __( 'new member' ),             'view' => __( 'view member' ),             'view_item' => __( 'view member' ),             'search_items' => __( 'search design team' ),             'not_found' => __( 'no info found' ),             'not_found_in_trash' => __( 'no info found in trash' ),             'parent' => __( 'parent info' ),             'menu_position' =>__( 7 ),            );          register_post_type( 'team' , $args );     } 

and called function can see in cms, add new entries, etc. need attach page template custom post type. on same site, have created custom post type named showroom, , attached custom post type page creating file called page-showroom.php. however, when create file called page-team.php, not associate page. syntax issue?

update got around creating page in cms, , adding template using page attributes. reason not particularly solution due possibility user change template of page, causing no longer work.

i feel missing relative how wp core defines page-?? variable template names or typo, stupid mistake, etc...

update requested, here code functions.php loads of cpt's

// custom post types add_action('init', 'register_showroom'); add_action('init', 'register_project_gallery'); add_action('init', 'register_slideshow'); add_action('init', 'register_team');   // add showroom function register_showroom(){     $args = array(         'label' => __('showroom'),         'singular_label' => __('showroom'),         'public' => true,         'show_ui' => true,         'capability_type' => 'post',         'hierarchical' => true,         'rewrite' => array("slug" => "showroom",'with_front' => true), // permalinks format         'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'page-attributes' ),         'add_new' => __( 'add new' ),         'add_new_item' => __( 'add new' ),         'edit' => __( 'edit' ),         'edit_item' => __( 'edit' ),         'new_item' => __( 'new' ),         'view' => __( 'view' ),         'view_item' => __( 'view' ),         'search_items' => __( 'search showroom' ),         'not_found' => __( 'no info found' ),         'not_found_in_trash' => __( 'no info found in trash' ),         'parent' => __( 'parent info' ),         'menu_position' =>__( 4 ),        );      register_post_type( 'showroom' , $args ); }   // add project gallery function register_project_gallery(){     $args = array(         'label' => __('project gallery'),         'singular_label' => __('project gallery'),         'public' => true,         'show_ui' => true,         'capability_type' => 'post',         'hierarchical' => true,         'rewrite' => array("slug" => "project-gallery",'with_front' => true), // permalinks format         'supports' => array( 'title', 'editor', 'thumbnail' ),         'add_new' => __( 'add new' ),         'add_new_item' => __( 'add new' ),         'edit' => __( 'edit' ),         'edit_item' => __( 'edit' ),         'new_item' => __( 'new' ),         'view' => __( 'view' ),         'view_item' => __( 'view' ),         'search_items' => __( 'search project gallery' ),         'not_found' => __( 'no info found' ),         'not_found_in_trash' => __( 'no info found in trash' ),         'parent' => __( 'parent info' ),         'menu_position' =>__( 5 ),        );      register_post_type( 'project_gallery' , $args ); }  // add slideshow function register_slideshow(){     $args = array(         'label' => __('homepage slideshow'),         'singular_label' => __('homepage slideshow'),         'public' => true,         'show_ui' => true,         'capability_type' => 'post',         'hierarchical' => true,         'rewrite' => array("slug" => "project-gallery",'with_front' => true), // permalinks format         'supports' => array( 'title', 'excerpt', 'thumbnail' ),         'add_new' => __( 'add new slide' ),         'add_new_item' => __( 'add new slide' ),         'edit' => __( 'edit' ),         'edit_item' => __( 'edit' ),         'new_item' => __( 'new' ),         'view' => __( 'view' ),         'view_item' => __( 'view' ),         'search_items' => __( 'search homepage slideshow' ),         'not_found' => __( 'no info found' ),         'not_found_in_trash' => __( 'no info found in trash' ),         'parent' => __( 'parent info' ),         'menu_position' =>__( 6 ),        );      register_post_type( 'slideshow' , $args ); }  // add design team function register_team(){     $args = array(         'label' => __('design team'),         'singular_label' => __('design team'),         'public' => true,         'show_ui' => true,         'capability_type' => 'post',         'hierarchical' => true,         'rewrite' => array("slug" => "design-team",'with_front' => true), // permalinks format         'supports' => array( 'title', 'editor', 'thumbnail' ),         'add_new' => __( 'add new member' ),         'add_new_item' => __( 'add new member' ),         'edit' => __( 'edit member' ),         'edit_item' => __( 'edit member' ),         'new_item' => __( 'new member' ),         'view' => __( 'view member' ),         'view_item' => __( 'view member' ),         'search_items' => __( 'search design team' ),         'not_found' => __( 'no info found' ),         'not_found_in_trash' => __( 'no info found in trash' ),         'parent' => __( 'parent info' ),         'menu_position' =>__( 7 ),        );      register_post_type( 'team' , $args ); }  

so can create page-showroom.php, page-project_gallery.php, single-project_gallery.php, single-showroom.php automatically attach correct cpt if create page-team.php, loads page.php.

here sample of page-showroom.php, works:

<?php /*  template name: showroom   */ ?>  <?php get_header(); ?>      <div id="primary" class="site-content showroom">         <div id="content" role="main">              <?php while ( have_posts() ) : the_post(); ?>                 <?php get_template_part( 'content', 'showroom' ); ?>             <?php endwhile; // end of loop. ?>          </div><!-- #content -->     </div><!-- #primary -->  </div> <?php get_footer(); ?> 

and page-team.php, not work

<?php /*  template name: team   */ ?>  <?php get_header(); ?>      <div id="primary" class="site-content team">         <div id="content" role="main">              <?php while ( have_posts() ) : the_post(); ?>                 <?php get_template_part( 'content', 'team' ); ?>                 <?php //comments_template( '', true ); ?>             <?php endwhile; // end of loop. ?>            </div><!-- #content -->     </div><!-- #primary -->  </div> <?php get_footer(); ?> 

i follow template hierarchy. in case -- , i'm assuming want page list posts post type = team -- mean creating page called "archive-team.php" under "page-templates" directory. alternatively, if want display single posts, use "single-team.php" instead. way you're supposed it, @ least. way , works me.

http://codex.wordpress.org/template_hierarchy


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -