prefix = framework_get_prefix();
/* Set up the widget options. */
$widget_options = array(
'classname' => 'pages',
'description' => esc_html__( 'Display your site\'s pages.', 'wordsmith' )
);
/* Set up the widget control options. */
$control_options = array(
'width' => 525,
'height' => 350
);
/* Create the widget. */
$this->WP_Widget( "{$this->prefix}-pages", __( 'Pages', 'wordsmith' ), $widget_options, $control_options );
}
/* Outputs the widget based on the arguments input through the widget controls. */
function widget( $args, $instance ) {
extract( $args );
/* Set up the arguments for the wp_list_pages() function. */
$args = array(
'sort_column' => $instance['sort_column'],
'sort_order' => $instance['sort_order'],
'depth' => intval( $instance['depth'] ),
'child_of' => intval( $instance['child_of'] ),
'authors' => !empty( $instance['authors'] ) ? join( ', ', $instance['authors'] ) : '',
'include' => !empty( $instance['include'] ) ? join( ', ', $instance['include'] ) : '',
'exclude' => !empty( $instance['exclude'] ) ? join( ', ', $instance['exclude'] ) : '',
'exclude_tree' => $instance['exclude_tree'],
'link_before' => $instance['link_before'],
'link_after' => $instance['link_after'],
'number' => intval( $instance['number'] ),
'offset' => intval( $instance['offset'] ),
'hierarchical' => !empty( $instance['hierarchical'] ) ? true : false,
'title_li' => false,
'echo' => false
);
/* Open the output of the widget. */
echo $before_widget;
/* If a title was input by the user, display it. */
if ( !empty( $instance['title'] ) )
echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
/* Get the pages list. */
echo '
' . str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages( $args ) ) . '
';
/* Close the theme's widget wrapper. */
echo $after_widget;
}
/* Updates the widget control options for the particular instance of the widget. */
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance = $new_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['depth'] = strip_tags( $new_instance['depth'] );
$instance['child_of'] = strip_tags( $new_instance['child_of'] );
$instance['exclude_tree'] = strip_tags( $new_instance['exclude_tree'] );
$instance['number'] = strip_tags( $new_instance['number'] );
$instance['offset'] = strip_tags( $new_instance['offset'] );
$instance['sort_column'] = $new_instance['sort_column'];
$instance['sort_order'] = $new_instance['sort_order'];
$instance['link_before'] = $new_instance['link_before'];
$instance['link_after'] = $new_instance['link_after'];
$instance['hierarchical'] = ( isset( $new_instance['hierarchical'] ) ? 1 : 0 );
return $instance;
}
/* Displays the widget control options in the Widgets admin screen. */
function form( $instance ) {
/* Set up the default form values. */
$defaults = array(
'title' => esc_attr__( 'Pages', 'wordsmith' ),
'depth' => 0,
'number' => '',
'offset' => '',
'child_of' => '',
'include' => array(),
'exclude' => array(),
'exclude_tree' => '',
'authors' => array(),
'link_before' => '',
'link_after' => '',
'hierarchical' => true,
'sort_column' => 'post_title',
'sort_order' => 'ASC'
);
/* Merge the user-selected arguments with the defaults. */
$instance = wp_parse_args( (array) $instance, $defaults );
$posts = get_posts( array( 'post_type' => 'page', 'post_status' => 'any', 'post_mime_type' => '', 'orderby' => 'title', 'order' => 'ASC', 'numberposts' => -1 ) );
$authors = array();
foreach ( $posts as $post )
$authors[$post->post_author] = get_the_author_meta( 'display_name', $post->post_author );
$sort_order = array( 'ASC' => esc_attr__( 'Ascending', 'wordsmith' ), 'DESC' => esc_attr__( 'Descending', 'wordsmith' ) );
$sort_column = array( 'post_author' => esc_attr__( 'Author', 'wordsmith' ), 'post_date' => esc_attr__( 'Date', 'wordsmith' ), 'ID' => esc_attr__( 'ID', 'wordsmith' ), 'menu_order' => esc_attr__( 'Menu Order', 'wordsmith' ), 'post_modified' => esc_attr__( 'Modified', 'wordsmith' ), 'post_name' => esc_attr__( 'Slug', 'wordsmith' ), 'post_title' => esc_attr__( 'Title', 'wordsmith' ) );
?>