Framework 33 – Add Custom Widget
1) – Create a folder under “ndframwork” called “widgets”
2) – Create a new file called “wd-widgetname.php” ( change widgetname in whatever you need )
3) – Copy and Paste this code :
<!—————- CODE ——————–>
<?php class banner_widget extends WP_Widget {
function banner_widget() {
parent::__construct( false, ‘Ask the | Banner’ );
}
function widget( $args, $instance ) {
extract($args);
echo $before_widget;
echo $before_title.$instance[‘title’].$after_title; ?>
<a href=”<?php the_field(‘banner_link’, ‘widget_’ . $args[‘widget_id’]); ?>” target=”_blank”><img src=”<?php the_field(‘banner_image’, ‘widget_’ . $args[‘widget_id’]); ?>” /></a>
<?php echo $after_widget;
}
function update( $new_instance, $old_instance ) {
return $new_instance;
}
function form( $instance ) {
$title = esc_attr($instance[‘title’]); ?>
<p><label for=”<?php echo $this->get_field_id(‘title’);?>”>
Titolo: <input class=”widefat” id=”<?php echo $this->get_field_id(‘title’);?>” name=”< ?php echo $this->get_field_name(‘title’);?>” type=”text” value=”” />
</label></p>
<?php
}
}
function register_banner_widgets() {
register_widget( ‘banner_widget’ );
}
add_action( ‘widgets_init’, ‘register_banner_widgets’ );
<!—————- END CODE ——————–>
4) Insert the contents of the widgets inside the :
function widget( $args, $instance ) {
5)Change all banner_widget and register_banner_widgets width the name of the new widget
6) Open function .php and copy and paste this 2 line, change wd-banner.php, width the new widget’s file name
/* *****************************************************************************
Custom Widgets
***************************************************************************** */
require_once(get_template_directory() . ‘/ndframework/widgets/wd-banner.php’);