-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpost_dropdown_custom_control.php
33 lines (31 loc) · 1.08 KB
/
post_dropdown_custom_control.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
if (class_exists('WP_Customize_Control'))
{
/**
* Class to create a custom post control
*/
class Post_Dropdown_Custom_control extends WP_Customize_Control
{
/**
* Render the content on the theme customizer page
*/
public function render_content()
{
?>
<label>
<span class="customize-post-dropdown"><?php echo esc_html( $this->label ); ?></span>
<select name="<?php echo $this->id; ?>" id="<?php echo $this->id; ?>">
<?php
$args = wp_parse_args($this->args, array('numberposts' => '-1'));
$posts = get_posts($args);
foreach ( $posts as $post ) {
echo '<option value="'.$post->ID.'" '.selected($this->value, $post->ID).'>'.$post->post_title.'</option>';
}
?>
</select>
</label>
<?php
}
}
}
?>