Created
December 1, 2015 10:39
-
-
Save vdwijngaert/a3295f3ecd1ad80036fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
class P4D_Siblings extends WP_Widget | |
{ | |
/** | |
* Sets up the widgets name etc | |
*/ | |
public function __construct() | |
{ | |
$widget_ops = array('classname' => 'p4d_siblings', 'description' => __('Use this widget to display a list of page siblings.')); | |
parent::__construct('p4d_siblings', __('P4D: Siblings', 'p4d'), $widget_ops); | |
} | |
/** | |
* Outputs the content of the widget | |
* | |
* @param array $args | |
* @param array $instance | |
*/ | |
public function widget($args, $instance) | |
{ | |
$options = wp_parse_args($instance, array( | |
'title' => '' | |
)); | |
$title = apply_filters('widget_title', $options['title'], $instance, $this->id_base); | |
echo $args['before_widget']; | |
?> | |
<?php if(!empty($title)) : ?> | |
<?php echo $args['before_title'] . $title . $args['after_title'];?> | |
<?php endif; ?> | |
<ul class="p4d-sibling-list"> | |
<?php | |
global $post; | |
wp_list_pages('child_of=' . $post->post_parent); | |
?> | |
</ul> | |
<?php | |
echo $args['after_widget']; | |
} | |
/** | |
* Outputs the options form on admin | |
* | |
* @param array $instance The widget options | |
*/ | |
public function form($instance) | |
{ | |
$instance = wp_parse_args($instance, array( | |
'title' => '' | |
)); | |
$title = $instance['title']; | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'p4d' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>"> | |
</p> | |
<?php | |
} | |
/** | |
* Processing widget options on save | |
* | |
* @param array $new_instance The new options | |
* @param array $old_instance The previous options | |
*/ | |
public function update($new_instance, $old_instance) | |
{ | |
$instance = array(); | |
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; | |
$instance['amount'] = (int) $new_instance['amount']; | |
return $instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment