array( 'Post Template' ) ) ); /* Get theme and templates variables. */ $themes = get_themes(); $theme = get_current_theme(); $templates = $themes[$theme]['Template Files']; $post_templates = array(); /* If there's an array of templates, loop through each template. */ if ( is_array( $templates ) ) { /* Set up a $base path that we'll use to remove from the file name. */ $base = array( trailingslashit( get_template_directory() ), trailingslashit( get_stylesheet_directory() ) ); /* Loop through the post templates. */ foreach ( $templates as $template ) { /* Remove the base (parent/child theme path) from the template file name. */ $basename = str_replace( $base, '', $template ); /* Get the template data. */ $template_data = implode( '', file( $template ) ); /* Make sure the name is set to an empty string. */ $name = ''; /* Loop through each of the potential labels and see if a match is found. */ foreach ( $args['label'] as $label ) { if ( preg_match( "|{$label}:(.*)$|mi", $template_data, $name ) ) { $name = _cleanup_header_comment( $name[1] ); break; } } /* If a post template was found, add its name and file name to the $post_templates array. */ if ( !empty( $name ) ) $post_templates[trim( $name )] = $basename; } } /* Return array of post templates. */ return $post_templates; } ?>