PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- // =============================== My Carousel widget ======================================
- class MY_FredCarouselWidget extends WP_Widget {
- /** constructor */
- function MY_FredCarouselWidget() {
- parent::WP_Widget(false, $name = 'My - FredCarousel');
- }
- /** @see WP_Widget::widget */
- function widget($args, $instance) {
- $title = apply_filters('widget_title', $instance['title']);
- $limit = apply_filters('widget_limit', $instance['limit']);
- $cats = apply_filters('widget_cats', $instance['cats']);
- $count = apply_filters('widget_count', $instance['count']);
- $thumb_w = apply_filters('widget_thumb_w', $instance['thumb_w']);
- $thumb_h = apply_filters('widget_thumb_h', $instance['thumb_h']);
- $show_type = apply_filters('widget_show_type', $instance['show_type']);
- if( ! $thumb_h = absint($instance["thumb_h"] )) $thumb_h=50;
- if( ! $thumb_w = absint($instance["thumb_w"] )) $thumb_w=50;
- //if( ! $category = $instance["category"] ) $category='';
- if( ! $show_type = $instance["show_type"] ) $show_type='post';
- ?>
- <?PHP echo $before_widget; ?>
- <?PHP if ( $title )
- echo $before_title . $title . $after_title; ?>
- <!-- Elastislide Carousel -->
- <div class="list_carousel">
- <ul id="foo2">
- <?PHP
- $carouselPosts = new WP_Query();
- echo $cats[1];
- foreach ($cats as $key => $value) {
- echo $key[$value];
- }
- $carouselPosts->query('category_name=offers'.'&showposts='.$count.'&post_type='.$show_type);
- ?>
- <?PHP while ($carouselPosts->have_posts()) : $carouselPosts->the_post(); ?>
- <li>
- <a href="<?PHP the_permalink() ?>" title="<?PHP the_title(); ?>" >
- <?PHP
- $thumb = get_post_thumbnail_id();
- $img_url = wp_get_attachment_url( $thumb,'sliderimg'); //get img URL
- $image = aq_resize( $img_url, $thumb_w, $thumb_h, true ); //resize & crop img
- if(has_post_thumbnail()) { ?>
- <img src="<?PHP echo $image ?>" alt="<?PHP the_title(); ?>" />
- <?PHP {} ?>
- </a>
- <div class="slidertitle">
- <a href="<?PHP the_permalink() ?>" rel="bookmark" title="Permanent Link to <?PHP the_title_attribute(); ?>">
- <?PHP the_title(); ?>
- </a>
- </div>
- <div class="excerpt">
- <?PHP $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,$limit); ?>
- </div>
- <a class="details" href="<?PHP the_permalink() ?>" title="<?PHP the_title(); ?>">details</a>
- </li>
- <?PHP endwhile; ?>
- </ul>
- <div class="caroNav">
- <a class="prev" id="prev2" href="#"><span>prev</span></a>
- <a class="next" id="next2" href="#"><span>next</span></a>
- </div>
- </div>
- <script type="text/javascript">
- jQuery(function($) {
- $('#foo2').carouFredSel({
- prev: '#prev2',
- next: '#next2',
- scroll : {
- items : 1,
- easing : "linear",
- duration : 500,
- pauseOnHover : true
- }
- });
- });
- </script>
- <!-- End Elastislide Carousel -->
- <?PHP echo $after_widget; ?>
- <?PHP
- }
- /** @see WP_Widget::update */
- function update($new_instance, $old_instance) {
- return $new_instance;
- }
- /** @see WP_Widget::form */
- function form($instance) {
- $title = esc_attr($instance['title']);
- $limit = esc_attr($instance['limit']);
- //$category = esc_attr($instance['category']);
- $count = esc_attr($instance['count']);
- $thumb_w = esc_attr($instance['thumb_w']);
- $thumb_h = esc_attr($instance['thumb_h']);
- $show_type = esc_attr($instance['show_type']);
- ?>
- <p><label for="<?PHP echo $this->get_field_id('title'); ?>"><?PHP _e('Title:'); ?> <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; ?>" /></label></p>
- <p><label for="<?PHP echo $this->get_field_id('limit'); ?>"><?PHP _e('Limit Text:'); ?> <input class="widefat" id="<?PHP echo $this->get_field_id('limit'); ?>" name="<?PHP echo $this->get_field_name('limit'); ?>" type="text" value="<?PHP echo $limit; ?>" /></label></p>
- <p><label for="<?PHP echo $this->get_field_id('count'); ?>"><?PHP _e('Number of posts to show:'); ?></label>
- <input id="<?PHP echo $this->get_field_id('count'); ?>" name="<?PHP echo $this->get_field_name('count'); ?>" type="text" value="<?PHP echo $count; ?>" size="3" /></p>
- <?PHP
- <p>
- <label for="<?PHP echo $this->get_field_id("thumb"); ?>">
- <input type="checkbox" class="checkbox" id="<?PHP echo $this->get_field_id("thumb"); ?>" name="<?PHP echo $this->get_field_name("thumb"); ?>"<?PHP checked( (bool) $instance["thumb"], true ); ?> />
- <?PHP _e( 'Show post thumbnail' ); ?>
- </label>
- </p>
- <p>
- <label>
- <?PHP _e('Thumbnail dimensions'); ?>:<br />
- <label for="<?PHP echo $this->get_field_id("thumb_w"); ?>">
- W: <input class="widefat" style="width:40%;" type="text" id="<?PHP echo $this->get_field_id("thumb_w"); ?>" name="<?PHP echo $this->get_field_name("thumb_w"); ?>" value="<?PHP echo $thumb_w; ?>" />
- </label>
- <label for="<?PHP echo $this->get_field_id("thumb_h"); ?>">
- H: <input class="widefat" style="width:40%;" type="text" id="<?PHP echo $this->get_field_id("thumb_h"); ?>" name="<?PHP echo $this->get_field_name("thumb_h"); ?>" value="<?PHP echo $thumb_h; ?>" />
- </label>
- </label>
- </p>
- <?PHP endif; ?>
- <p>
- <label for="<?PHP echo $this->get_field_id('cats'); ?>"><?PHP _e('Categories:');?>
- <!-- <select class="widefat" id="<?PHP echo $this->get_field_id('show_type'); ?>" name="<?PHP echo $this->get_field_name('show_type'); ?>">
- <?PHP
- /*global $wp_post_types;
- foreach($wp_post_types as $k=>$sa) {
- if($sa->exclude_from_search) continue;
- echo '<option value="' . $k . '"' . selected($k,$show_type,true) . '>' . $sa->labels->name . '</option>';*/
- //}
- ?>
- </select> -->
- <?PHP
- $categories= get_categories('hide_empty=0');
- echo "<br/>";
- foreach ($categories as $cat) {
- $option='<input type="checkbox" id="'. $this->get_field_id( 'cats' ) .'[]" name="'. $this->get_field_name( 'cats' ) .'[]"';
- foreach ($instance['cats'] as $cats) {
- if($cats==$cat->term_id) {
- $option=$option.' checked="checked"';
- }
- }
- }
- $option .= ' value="'.$cat->term_id.'" />';
- $option .= $cat->cat_name;
- $option .= '<br />';
- echo $option;
- }
- ?>
- </label>
- </p>
- <p>
- <label for="<?PHP echo $this->get_field_id('show_type'); ?>"><?PHP _e('Show Post Type:');?>
- <select class="widefat" id="<?PHP echo $this->get_field_id('show_type'); ?>" name="<?PHP echo $this->get_field_name('show_type'); ?>">
- <?PHP
- global $wp_post_types;
- foreach($wp_post_types as $k=>$sa) {
- if($sa->exclude_from_search) continue;
- echo '<option value="' . $k . '"' . selected($k,$show_type,true) . '>' . $sa->labels->name . '</option>';
- }
- ?>
- </select>
- </label>
- </p>
- <?PHP
- }
- } // class Carousel Widget
- ?>