-
-
Save imrantushar/3b06916382fe2a4088479d62c5de0b4c to your computer and use it in GitHub Desktop.
Custom Theme Customization Controls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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' | |
) | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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', | |
), | |
) | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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', | |
), | |
) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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', | |
) | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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