page_template_dropdown

Print out option HTML elements for the page templates drop-down.

Description

page_template_dropdown( (string) $default = '', (string) $post_type = 'page' ); 

Parameters (2)

0. $default — Optional. (string) => ''
The template file name. Default empty.
1. $post_type — Optional. (string) => 'page'
Post type to get templates for. Default post..

Usage

  1. if ( !function_exists( 'page_template_dropdown' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // Optional. The template file name. Default empty. 
  5. $default = ''; 
  6.  
  7. // Optional. Post type to get templates for. Default 'post'. 
  8. $post_type = 'page'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = page_template_dropdown($default, $post_type); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function page_template_dropdown( $default = '', $post_type = 'page' ) { 
  2. $templates = get_page_templates( null, $post_type ); 
  3. ksort( $templates ); 
  4. foreach ( array_keys( $templates ) as $template ) { 
  5. $selected = selected( $default, $templates[ $template ], false ); 
  6. echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";