Created
March 30, 2011 15:40
-
-
Save mrchrisadams/894630 to your computer and use it in GitHub Desktop.
This file contains 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 Post_Gallery_Widget extends WP_Widget { | |
/** constructor */ | |
function Post_Gallery_Widget() { | |
parent::WP_Widget( | |
false, | |
$name = 'Gallery Widget ', | |
$widget_options = array( | |
'description' => "A gallery for listing images for a given post/page, for using with Page Layout", | |
) | |
); | |
add_action( 'save_post', array(&$this, 'flush_widget_cache') ); | |
add_action( 'deleted_post', array(&$this, 'flush_widget_cache') ); | |
add_action( 'switch_theme', array(&$this, 'flush_widget_cache') ); | |
} | |
/** @see WP_Widget::widget */ | |
function widget($args, $instance) { | |
extract( $args ); | |
$cache = wp_cache_get('widget_page_gallery', 'widget'); | |
$title = apply_filters('widget_title', $instance['title']); | |
// we only want to run this on the front end of the site, and only | |
// want one jquery | |
if ( !is_admin() ) { | |
wp_register_script( | |
'jquery-cycle', | |
get_bloginfo('template_directory') . 'js/jquery.cycle.lite.1.1.js', | |
array('jquery'), | |
'0.1' | |
); | |
print wp_enqueue_script('jquery-cycle'); | |
die("no, I don't know why jquery isn't loading either"); | |
} | |
// generate markup for each widget | |
echo $before_widget; | |
// sadly this seems to be the most readable way to pass args into | |
// this gallery function | |
// settings defined in the form will be added here | |
echo do_shortcode('[gallery columns="1" size="medium"]'); | |
// add the jquery cycle call here | |
echo $after_widget; | |
} | |
/** @see WP_Widget::update */ | |
function update($new_instance, $old_instance) { | |
// create a back up we we an access it when updating content | |
$instance = $old_instance; | |
$instance['title'] = strip_tags($new_instance['title']); | |
return $instance; | |
} | |
/** @see WP_Widget::form */ | |
function form($instance) { | |
$title = esc_attr($instance['title']); | |
?> | |
<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 $title; ?>" /> | |
</p> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment