I am using WordPress' Theme Customizer where I would like to add an option for the user to select the page template used.
Here is the code to get the page templates. This is the section that needs fixing. I borrowed this first block of code that gets the slugs of a category. Now I need to modify it to load page template as a menu option.
function get_page_templates_select() {
$teh_cats = get_page_templates();
$results;
$count = count($teh_cats);
for ($i=0; $i < $count; $i++) {
if (isset($teh_cats[$i]))
$results[$teh_cats[$i]->slug] = $teh_cats[$i]->name;
else
$count++;
}
return $results;
}
Here I add the control to the Theme Customizer:
$wp_customize->add_setting( 'home_page_template_select' , array(
'default' => 'test',
'type' => 'option',
'transport' => 'refresh',
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'home_page_template_select',
array(
'label' => __( 'Home page template:', 'blankwptheme' ),
'section' => 'prowordpress_content_customizations',
'settings' => 'home_page_template_select',
'type' => 'select',
'choices' => get_page_templates_select(),
)
)
);
When I run this code, the Theme Customizer times out. How can I modify the get_page_templates_select function to load properly into the control (select menu)?
EDIT:
Here is the new function I am playing around with:
function get_page_templates_select() {
$teh_cats = get_page_templates();
foreach ( $teh_cats as $template_name => $template_filename ) {
$results[] = $template_name;
}
return $results;
}
get_page_templates
for an example of what is returned by that function.