Index: src/wp-admin/edit-form-advanced.php
===================================================================
--- src/wp-admin/edit-form-advanced.php	(revisione 38298)
+++ src/wp-admin/edit-form-advanced.php	(copia locale)
@@ -259,8 +259,7 @@
 	add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) );
 }
 
-if ( post_type_supports($post_type, 'page-attributes') )
-	add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core');
+add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core');
 
 if ( $thumbnail_support && current_user_can( 'upload_files' ) )
 	add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low');
Index: src/wp-admin/includes/meta-boxes.php
===================================================================
--- src/wp-admin/includes/meta-boxes.php	(revisione 38298)
+++ src/wp-admin/includes/meta-boxes.php	(copia locale)
@@ -785,6 +785,7 @@
  * @param object $post
  */
 function page_attributes_meta_box($post) {
+  if ( post_type_supports($post->post_type, 'page-attributes') ) {
 	$post_type_object = get_post_type_object($post->post_type);
 	if ( $post_type_object->hierarchical ) {
 		$dropdown_args = array(
@@ -817,7 +818,8 @@
 <?php
 		} // end empty pages check
 	} // end hierarchical check.
-	if ( 'page' == $post->post_type && 0 != count( get_page_templates( $post ) ) && get_option( 'page_for_posts' ) != $post->ID ) {
+  }
+	if ( 0 != count( get_page_templates( $post ) ) ) {
 		$template = !empty($post->page_template) ? $post->page_template : false;
 		?>
 <p><strong><?php _e('Template') ?></strong><?php
@@ -832,7 +834,7 @@
 	 */
 	do_action( 'page_attributes_meta_box_template', $template, $post );
 ?></p>
-<label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select name="page_template" id="page_template">
+<label class="screen-reader-text" for="page_template"><?php _e('Template') ?></label><select name="page_template" id="page_template">
 <?php
 /**
  * Filters the title of the default page template displayed in the drop-down.
@@ -846,15 +848,17 @@
 $default_title = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'meta-box' );
 ?>
 <option value="default"><?php echo esc_html( $default_title ); ?></option>
-<?php page_template_dropdown($template); ?>
+<?php post_type_template_dropdown($template, $post->post_type); ?>
 </select>
 <?php
-	} ?>
+	} 
+	if ( post_type_supports($post->post_type, 'page-attributes') ) {?>
 <p><strong><?php _e('Order') ?></strong></p>
 <p><label class="screen-reader-text" for="menu_order"><?php _e('Order') ?></label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order) ?>" /></p>
-<?php if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) { ?>
+<?php	  if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) { ?>
 <p><?php _e( 'Need help? Use the Help tab above the screen title.' ); ?></p>
 <?php
+	  }
 	}
 }
 
Index: src/wp-admin/includes/template.php
===================================================================
--- src/wp-admin/includes/template.php	(revisione 38298)
+++ src/wp-admin/includes/template.php	(copia locale)
@@ -296,8 +296,7 @@
 	if ( $post_type_object->hierarchical )
 		echo '<div class="post_parent">' . $post->post_parent . '</div>';
 
-	if ( $post->post_type == 'page' )
-		echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
+	echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
 
 	if ( post_type_supports( $post->post_type, 'page-attributes' ) )
 		echo '<div class="menu_order">' . $post->menu_order . '</div>';
@@ -758,14 +757,15 @@
 }
 
 /**
- * Print out option HTML elements for the page templates drop-down.
+ * Display dropdown options for template files from the active theme 
  *
- * @since 1.5.0
+ * @since 4.8.0
  *
  * @param string $default Optional. The template file name. Default empty.
+ * @param string $post_type Post type 
  */
-function page_template_dropdown( $default = '' ) {
-	$templates = get_page_templates( get_post() );
+function post_type_template_dropdown( $default = '', $post_type = 'page' ) { 
+	$templates = get_post_type_templates( null, $post_type );
 	ksort( $templates );
 	foreach ( array_keys( $templates ) as $template ) {
 		$selected = selected( $default, $templates[ $template ], false );
@@ -774,6 +774,17 @@
 }
 
 /**
+ * Print out option HTML elements for the page templates drop-down.
+ *
+ * @since 1.5.0
+ *
+ * @param string $default Optional. The template file name. Default empty.
+ */
+function page_template_dropdown( $default = '' ) { 
+ 	post_type_template_dropdown( $default, 'page' ); 
+}
+
+/**
  * Print out option HTML elements for the page parents drop-down.
  *
  * @since 1.5.0
Index: src/wp-admin/includes/theme.php
===================================================================
--- src/wp-admin/includes/theme.php	(revisione 38298)
+++ src/wp-admin/includes/theme.php	(copia locale)
@@ -99,6 +99,19 @@
 }
 
 /**
+ * Get the Templates available in this theme
+ *
+ * @since 4.8.0
+ *
+ * @param WP_Post|null $post Optional. The post being edited, provided for context.
+ * @param string $post_type Optional. The post type templates to find
+ * @return array Key is the template name, value is the filename of the template
+ */
+function get_post_type_templates( $post = null, $post_type = null ) { 
+	return array_flip( wp_get_theme()->get_post_templates( $post, $post_type ) );
+} 
+
+/**
  * Get the Page Templates available in this theme
  *
  * @since 1.5.0
@@ -107,7 +120,7 @@
  * @return array Key is the template name, value is the filename of the template
  */
 function get_page_templates( $post = null ) {
-	return array_flip( wp_get_theme()->get_page_templates( $post ) );
+	return array_flip( wp_get_theme()->get_post_templates( $post, 'page' ) );
 }
 
 /**
Index: src/wp-includes/class-wp-theme.php
===================================================================
--- src/wp-includes/class-wp-theme.php	(revisione 38298)
+++ src/wp-includes/class-wp-theme.php	(copia locale)
@@ -1014,14 +1014,28 @@
 	 * @return array Array of page templates, keyed by filename, with the value of the translated header name.
 	 */
 	public function get_page_templates( $post = null ) {
+	  return (array) apply_filters( 'theme_page_templates', $this->get_post_templates($post, 'page'), $this, $post );
+	}
+	
+	/**
+	 * Returns the theme's post type templates.
+	 *
+	 * @since 4.8.0
+	 * @access public
+	 *
+	 * @param WP_Post|null $post Optional. The post being edited, provided for context.
+	 * @param string $post_type Optional. The post type templates to find
+	 * @return array Array of page templates, keyed by filename, with the value of the translated header name.
+	 */
+	public function get_post_templates( $post = null, $post_type = 'page' ) {
 		// If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
 		if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) )
 			return array();
 
-		$page_templates = $this->cache_get( 'page_templates' );
+		$post_templates = $this->cache_get( 'post_templates' );
 
-		if ( ! is_array( $page_templates ) ) {
-			$page_templates = array();
+		if ( ! is_array( $post_templates ) ) {
+			$post_templates = array();
 
 			$files = (array) $this->get_files( 'php', 1 );
 
@@ -1028,20 +1042,32 @@
 			foreach ( $files as $file => $full_path ) {
 				if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) )
 					continue;
-				$page_templates[ $file ] = _cleanup_header_comment( $header[1] );
+				$post_templates[ $file ] = _cleanup_header_comment( $header[1] );
+				if ( preg_match( '|Template Type:(.*)$|mi', file_get_contents( $full_path ), $type ) )  {
+ 		                $types = explode( ',', _cleanup_header_comment( $type[1] ) ); 
+				} else {
+ 		                $types = array( 'page' ); 
+				}
+				foreach ( $types as $type ) { 
+ 		                $type = trim( $type ); 
+ 		                if ( !isset( $post_templates[$type] ) ) {
+ 		                      $post_templates[$type] = array(); 
+ 		                      $post_templates[$type][$file] = _cleanup_header_comment( $header[1] );
+				    }
+ 		            }
 			}
 
-			$this->cache_add( 'page_templates', $page_templates );
+			$this->cache_add( 'post_templates', $post_templates );
 		}
 
 		if ( $this->load_textdomain() ) {
-			foreach ( $page_templates as &$page_template ) {
-				$page_template = $this->translate_header( 'Template Name', $page_template );
+			foreach ( $post_templates as &$post_template ) {
+				$post_templates = $this->translate_header( 'Template Name', $post_template[$post_type] );
 			}
 		}
 
 		if ( $this->parent() )
-			$page_templates += $this->parent()->get_page_templates( $post );
+			$post_templates += $this->parent()->get_post_templates( $post, $post_type );
 
 		/**
 		 * Filters list of page templates for a theme.
@@ -1054,7 +1080,7 @@
 		 * @param WP_Theme     $this           The theme object.
 		 * @param WP_Post|null $post           The post being edited, provided for context, or null.
 		 */
-		return (array) apply_filters( 'theme_page_templates', $page_templates, $this, $post );
+		return (array) apply_filters( 'theme_post_templates', $post_templates[$post_type], $this, $post );
 	}
 
 	/**
Index: src/wp-includes/post-template.php
===================================================================
--- src/wp-includes/post-template.php	(revisione 38298)
+++ src/wp-includes/post-template.php	(copia locale)
@@ -1580,9 +1580,6 @@
  * @return bool True on success, false on failure.
  */
 function is_page_template( $template = '' ) {
-	if ( ! is_page() )
-		return false;
-
 	$page_template = get_page_template_slug( get_queried_object_id() );
 
 	if ( empty( $template ) )
Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revisione 38298)
+++ src/wp-includes/post.php	(copia locale)
@@ -3307,9 +3307,9 @@
 
 	$post = get_post( $post_ID );
 
-	if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type'] ) {
+	if ( ! empty( $postarr['page_template'] ) ) {
 		$post->page_template = $postarr['page_template'];
-		$page_templates = wp_get_theme()->get_page_templates( $post );
+		$page_templates = wp_get_theme()->get_post_templates( $post->post_type );
 		if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
 			if ( $wp_error ) {
 				return new WP_Error('invalid_page_template', __('The page template is invalid.'));
Index: src/wp-includes/template.php
===================================================================
--- src/wp-includes/template.php	(revisione 38298)
+++ src/wp-includes/template.php	(copia locale)
@@ -391,9 +391,17 @@
  */
 function get_single_template() {
 	$object = get_queried_object();
+	$template = get_post_meta( $object->ID, '_wp_page_template', true ); 
+	
+	if ( 'default' === $template ) 
+ 	      $template = ''; 
 
 	$templates = array();
-
+	
+	if ( !empty($template) && !validate_file($template) ) {
+ 	      $templates[] = $template; 
+	}
+	
 	if ( ! empty( $object->post_type ) ) {
 		$templates[] = "single-{$object->post_type}-{$object->post_name}.php";
 		$templates[] = "single-{$object->post_type}.php";
