This is how I created the custom post type
function wp_custom_post_type_listing()
{
$labels = array(
'name' => _x('Listing', 'post type general name', 'wpprolister'),
'singular_name' => _x('Listing', 'post type singular name' ,'wpprolister'),
'add_new' => _x('Add new listing', 'l', 'wpprolister'),
'all_item' => __('All Listing', 'wpprolister'),
'add_new_item' => __('Add new listing', 'wpprolister'),
'edit_item' => __('Edit Listing', 'wpprolister'),
'new_item' => __('New Listing', 'wpprolister'),
'view_item' => __('View Listing', 'wpprolister'),
'search_item' => __('Search Listing', 'wpprolister'),
'not_found' => __('No Listing found', 'wpprolister'),
'not_found_in_trash' => __('No listings found in trash', 'wpprolister'),
'parent_item_colon' => __('Parent Listing', 'wpprolister'),
);
$args_listing = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => true,
'menu_icon' => plugins_url( 'images/list.png', __FILE__ ),
'capability_type' => 'listing',
'capabilities' => array(
'edit_post' => 'edit_listing',
'read_post' => 'read_listing',
'delete_post' => 'delete_listing',
'edit_posts' => 'edit_listings',
'edit_others_posts' => 'edit_others_listings',
'publish_posts' => 'publish_listings',
'read_private_posts' => 'read_private_listings',
'create_posts' => 'edit_listings',
'delete_posts' => 'delete_listings',
'delete_published_posts' => 'delete_published_listing',
'delete_others_posts' => 'delete_others_listings',
'edit_published_posts' => 'edit_published_listings',
),
'hierarchical' => false,
'map_meta_cap' => false,
'supports' => array(
'title',
'editor',
'expert',
'thumbnail',
'comments',
'page-attributes',
),
'taxonomies' => array('listing_categories', 'locations', 'amenities', 'post_tag'),
'menu_position' => 2,
'exclude_from_search' => false,
);
register_post_type('l', $args_listing);
}
But the post attribute to select a post template does not show up.
I have added in the template page-fullwidth.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
/*
Template Name: Full Width
Template Post Type: post, page , l
*/
get_header();
get_template_part( '/wpprolister-templates/content', 'titlebar'); ?>
I already have a template assigned for the custom post type
single-l.php
but I want an additional post template
This is how I created the custom post type
function wp_custom_post_type_listing()
{
$labels = array(
'name' => _x('Listing', 'post type general name', 'wpprolister'),
'singular_name' => _x('Listing', 'post type singular name' ,'wpprolister'),
'add_new' => _x('Add new listing', 'l', 'wpprolister'),
'all_item' => __('All Listing', 'wpprolister'),
'add_new_item' => __('Add new listing', 'wpprolister'),
'edit_item' => __('Edit Listing', 'wpprolister'),
'new_item' => __('New Listing', 'wpprolister'),
'view_item' => __('View Listing', 'wpprolister'),
'search_item' => __('Search Listing', 'wpprolister'),
'not_found' => __('No Listing found', 'wpprolister'),
'not_found_in_trash' => __('No listings found in trash', 'wpprolister'),
'parent_item_colon' => __('Parent Listing', 'wpprolister'),
);
$args_listing = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => true,
'menu_icon' => plugins_url( 'images/list.png', __FILE__ ),
'capability_type' => 'listing',
'capabilities' => array(
'edit_post' => 'edit_listing',
'read_post' => 'read_listing',
'delete_post' => 'delete_listing',
'edit_posts' => 'edit_listings',
'edit_others_posts' => 'edit_others_listings',
'publish_posts' => 'publish_listings',
'read_private_posts' => 'read_private_listings',
'create_posts' => 'edit_listings',
'delete_posts' => 'delete_listings',
'delete_published_posts' => 'delete_published_listing',
'delete_others_posts' => 'delete_others_listings',
'edit_published_posts' => 'edit_published_listings',
),
'hierarchical' => false,
'map_meta_cap' => false,
'supports' => array(
'title',
'editor',
'expert',
'thumbnail',
'comments',
'page-attributes',
),
'taxonomies' => array('listing_categories', 'locations', 'amenities', 'post_tag'),
'menu_position' => 2,
'exclude_from_search' => false,
);
register_post_type('l', $args_listing);
}
But the post attribute to select a post template does not show up.
I have added in the template page-fullwidth.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
/*
Template Name: Full Width
Template Post Type: post, page , l
*/
get_header();
get_template_part( '/wpprolister-templates/content', 'titlebar'); ?>
I already have a template assigned for the custom post type
single-l.php
but I want an additional post template
1 Answer
Reset to default 0If I understand your question correctly, you need option to select page template in a custom post type. In order to do that you have to take a different approach.
In your page-fullwidth.php
add template name using the following code:
/*
Template Name: Full-width layout
Template Post Type: l
*/
get_header();
In theory, the default template should fall back to single-l.php
but if not please do let me know.
Also to clear out the misunderstanding on page_attributes
argument, it only provides option for selecting menu order and selecting a parent if hierarchical
is set to true.