git-svn-id: https://192.168.0.254/svn/Proyectos.EstudioJuridicoAlmagro_Web/trunk@3 c22fe52d-42d7-ba4f-95f7-33effcf65713
63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* list either subpages or siblings
|
|
*/
|
|
|
|
class wpv_subpages extends WP_Widget {
|
|
|
|
public function wpv_subpages() {
|
|
$widget_ops = array(
|
|
'classname' => 'wpv_subpages',
|
|
'description' => __('Displays a list of SubPages', 'wpv')
|
|
);
|
|
$this->WP_Widget('wpv_subpages', __('Vamtam - List subpages', 'wpv') , $widget_ops);
|
|
}
|
|
|
|
function widget($args, $instance) {
|
|
global $post;
|
|
$children = wp_list_pages('echo=0&child_of=' . $post->ID . '&title_li=');
|
|
|
|
if($children)
|
|
$parent = $post->ID; // try listing children
|
|
else {
|
|
$parent = $post->post_parent; // try siblings
|
|
if(!$parent)
|
|
$parent = $post->ID;
|
|
}
|
|
$parent_title = get_the_title($parent);
|
|
extract($args);
|
|
$title = apply_filters('widget_title', empty($instance['title']) ? $parent_title : $instance['title'], $instance, $this->id_base);
|
|
$sortby = empty($instance['sortby']) ? 'menu_order' : $instance['sortby'];
|
|
$exclude = $instance['exclude'];
|
|
|
|
require WPV_WIDGETS_TPL . 'subpages-widget.php';
|
|
}
|
|
|
|
function update($new_instance, $old_instance) {
|
|
$instance = $old_instance;
|
|
$instance['title'] = strip_tags($new_instance['title']);
|
|
|
|
if(in_array($new_instance['sortby'], array('post_title', 'menu_order', 'ID')))
|
|
$instance['sortby'] = $new_instance['sortby'];
|
|
else
|
|
$instance['sortby'] = 'menu_order';
|
|
|
|
$instance['exclude'] = strip_tags($new_instance['exclude']);
|
|
|
|
return $instance;
|
|
}
|
|
|
|
function form($instance) {
|
|
$instance = wp_parse_args((array)$instance, array(
|
|
'sortby' => 'menu_order',
|
|
'title' => '',
|
|
'exclude' => ''
|
|
));
|
|
$title = esc_attr($instance['title']);
|
|
$exclude = esc_attr($instance['exclude']);
|
|
|
|
require WPV_WIDGETS_TPL . 'subpages-config.php';
|
|
}
|
|
}
|
|
register_widget('wpv_subpages'); |