Exemplo n.º 1
0
function theme_widgets_ajax_callback() {
    $query = $_POST['query'];
    switch ($query) {
        case 'get_parent_posts':
            $ptype = $_POST['post_type'];
            $posts = get_theme_widgets_posts($ptype);
            if (!empty($posts)) {
                $options = '';
                foreach ($posts as $post) {
                    $options .= sprintf('<option value="%1$s" selected>%2$s</option>', $post->ID, $post->post_title);
                }
                $segments = array('parent_pages' => $options);
                echo json_encode($segments);
            }
            break;
    }
    exit();
}
Exemplo n.º 2
0
    /**
     * Outputs the options form on admin
     *
     * @param array $instance The widget options
     */
    public function form($instance) {

        $title = !empty($instance['title']) ? $instance['title'] : __('', 'uiu');
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></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
        $post_type = !empty($instance['post_type']) ? $instance['post_type'] : 'page';
        $post_types = get_post_types(array('public' => TRUE, 'hierarchical' => TRUE));
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('post_type'); ?>"><?php _e('Post Type:'); ?></label> 
            <select  data-target="#<?php echo $this->get_field_id('post_parent'); ?>" name="<?php echo $this->get_field_name('post_type'); ?>" id="<?php echo $this->get_field_id('post_type'); ?>" onchange="THEME_WIDGETS.getPost(this)">
        <?php
        //$post_types = get_post_types( array('public'=>TRUE,'hierarchical'=>TRUE));
        foreach ($post_types as $key => $type) {
            if ($type == $post_type) {
                echo sprintf('<option value="%1$s" selected>%1$s</option>', $key, ucwords($type));
            } else {
                echo sprintf('<option value="%1$s">%1$s</option>', $key, ucwords($type));
            }
        }
        ?>              
            </select>
        </p>
                <?php
                $post_parent = !empty($instance['post_parent']) ? $instance['post_parent'] : 0;
                $post_parents = get_theme_widgets_posts($post_type);
                ?>
        <p>
            <label for="<?php echo $this->get_field_id('post_parent'); ?>"><?php _e('Post Parent:'); ?></label> 
            <select name="<?php echo $this->get_field_name('post_parent'); ?>" id="<?php echo $this->get_field_id('post_parent'); ?>">
        <?php
        foreach ($post_parents as $post) {
            if ($post->ID == $post_parent) {
                echo sprintf('<option value="%1$s" selected>%2$s</option>', $post->ID, $post->post_title);
            } else {
                echo sprintf('<option value="%1$s">%2$s</option>', $post->ID, $post->post_title);
            }
        }
        ?>
            </select>
        </p>      
        <fieldset class="theme-widgets">
            <legend>Slider Settings</legend>
        <?php $autoplay = !empty($instance['carousel_auto_play']) ? 1 : 0; ?>
            <p>
                <label for="<?php echo $this->get_field_id('carousel_auto_play'); ?>"><?php _e('Auto Play:'); ?> <input name="<?php echo $this->get_field_name('carousel_auto_play'); ?>" id="<?php echo $this->get_field_id('carousel_auto_play'); ?>" type="checkbox" value="1" <?php if ($autoplay) {
            echo 'checked=""';
        } ?>/></label> 
            </p>
            <?php $nav = !empty($instance['carousel_nav']) ? 1 : 0; ?>
            <p>
                <label for="<?php echo $this->get_field_id('carousel_nav'); ?>"><?php _e('Navigation:'); ?> <input name="<?php echo $this->get_field_name('carousel_nav'); ?>" id="<?php echo $this->get_field_id('carousel_nav'); ?>" type="checkbox" value="1" <?php if ($nav) {
                echo 'checked=""';
            } ?>/></label> 
            </p>
        <?php $pagging = !empty($instance['carousel_pagging']) ? 1 : 0; ?>
            <p>
                <label for="<?php echo $this->get_field_id('carousel_pagging'); ?>"><?php _e('Pagging:'); ?> <input name="<?php echo $this->get_field_name('carousel_pagging'); ?>" id="<?php echo $this->get_field_id('carousel_pagging'); ?>" type="checkbox" value="1" <?php if ($pagging) {
            echo 'checked=""';
        } ?>/></label> 
            </p>
        </fieldset>
        <?php
    }