Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Description: Video Widget grabs posts from your video category and the associated thumbnail to display on your sidebar.
- Version: 1
- */
- class YounesVideoWidget extends WP_Widget
- {
- function YounesVideoWidget()
- {
- $widget_ops = array('classname' => 'YounesVideoWidget', 'description' => 'Video Widget grabs posts from your video category and the associated thumbnail to display on your sidebar.' );
- $this->WP_Widget('YounesVideoWidget', 'YOUNES: Video Widget', $widget_ops);
- }
- function form($instance)
- {
- $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
- $title = $instance['title'];
- ?>
- <p><label for="<?php echo $this->get_field_id('title'); ?>">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 attribute_escape($title); ?>" /></label></p>
- <p>
- <label for="<?php echo $this->get_field_id('category1'); ?>"><?php _e('Category:'); ?></label>
- <select id="<?php echo $this->get_field_id('category1'); ?>" name="<?php echo $this->get_field_name('category1'); ?>" style="width:90%;">
- <option value="0">Choose category:</option>
- <?php
- $cats = get_categories('hide_empty=0');
- foreach ($cats as $cat) {
- $option = '<option value="'.$cat->term_id;
- if ($cat->term_id == $instance['category1']) { $option .='" selected="selected';}
- $option .= '">';
- $option .= $cat->cat_name;
- $option .= ' ('.$cat->category_count.')';
- $option .= '</option>';
- echo $option;
- }
- ?>
- </select>
- </p>
- <?php
- }
- function update($new_instance, $old_instance)
- {
- $instance = $old_instance;
- $instance['title'] = $new_instance['title'];
- return $instance;
- }
- function widget($args, $instance)
- {
- extract($args, EXTR_SKIP);
- echo $before_widget;
- $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
- if (!empty($title))
- echo $before_title . $title . $after_title;;
- /* Widget */
- $custom = new WP_Query('posts_per_page=4&cat=13&orderby=date');
- if ($custom->have_posts()) :
- echo "<ul>";
- while ($custom->have_posts()) : $custom->the_post();
- echo "<li class='photo'><a href='".get_permalink()."'>";
- echo "<img src='wp-content/themes/tribune2.1.7/images/1.gif' class='play'>";
- the_post_thumbnail($post_id, 'medium');
- echo ShortTitle(get_the_title());
- echo "</a></li>";
- endwhile;
- echo "</ul>";
- endif; wp_reset_postdata();
- echo $after_widget;
- }
- }
- add_action( 'widgets_init', create_function('', 'return register_widget("YounesVideoWidget");') );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement