Skip to content

Instantly share code, notes, and snippets.

@imrantushar
Forked from danielpataki/latestposts-control.php
Created December 2, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imrantushar/3b06916382fe2a4088479d62c5de0b4c to your computer and use it in GitHub Desktop.
Save imrantushar/3b06916382fe2a4088479d62c5de0b4c to your computer and use it in GitHub Desktop.
Custom Theme Customization Controls
$wp_customize->add_control(
new WP_Customize_Latest_Post_Control(
$wp_customize,
'featpost_control',
array(
'label' => __( 'Select A Featured Post', 'mytheme' ),
'section' => 'header_section',
'settings' => 'featured_post',
'post_type' => 'page'
)
)
);
if( class_exists( 'WP_Customize_Control' ) ):
class WP_Customize_Latest_Post_Control extends WP_Customize_Control {
public $type = 'latest_post_dropdown';
public $post_type = 'post';
public function render_content() {
$latest = new WP_Query( array(
'post_type' => $this->post_type,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
));
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<select <?php $this->link(); ?>>
<?php
while( $latest->have_posts() ) {
$latest->the_post();
echo "<option " . selected( $this->value(), get_the_ID() ) . " value='" . get_the_ID() . "'>" . the_title( '', '', false ) . "</option>";
}
?>
</select>
</label>
<?php
}
}
endif;
if( class_exists( 'WP_Customize_Control' ) ):
class WP_Customize_Latest_Post_Control extends WP_Customize_Control {
public $type = 'latest_post_dropdown';
public function render_content() {
$latest = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
));
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<select <?php $this->link(); ?>>
<?php
while( $latest->have_posts() ) {
$latest->the_post();
echo "<option " . selected( $this->value(), get_the_ID() ) . " value='" . get_the_ID() . "'>" . the_title( '', '', false ) . "</option>";
}
?>
</select>
</label>
<?php
}
}
endif;
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'sidebar_position_control',
array(
'label' => __( 'Sidebar Position', 'mytheme' ),
'section' => 'sidebar_settings',
'settings' => 'sidebar_position',
'type' => 'radio',
'choices' => array(
'left' => 'Left',
'right' => 'Right',
),
)
)
);
$wp_customize->add_control( 'sidebar_position_control', array(
'label' => __( 'Sidebar Position', 'mytheme' ),
'section' => 'sidebar_settings',
'settings' => 'sidebar_position',
'type' => 'radio',
'choices' => array(
'left' => 'Left',
'right' => 'Right',
),
) );
$wp_customize->add_control( new WP_Customize_Textarea_Control(
$wp_customize,
'footer_credits_control',
array(
'label' => __( 'Footer Credits', 'themename' ),
'section' => 'footer_settings',
'settings' => 'footer_credits',
)
));
if( class_exists( 'WP_Customize_Control' ) ):
class WP_Customize_Textarea_Control extends WP_Customize_Control {
public $type = 'textarea';
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<textarea rows="5" style="width:100%;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
</label>
<?php
}
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment