Advertisement
jamesnet

Untitled

Apr 22nd, 2013
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.75 KB | None | 0 0
  1. <?php
  2. /*
  3. Description: Video Widget grabs posts from your video category and the associated thumbnail to display on your sidebar.
  4. Version: 1
  5. */
  6.  
  7.  
  8. class YounesVideoWidget extends WP_Widget
  9. {
  10.   function YounesVideoWidget()
  11.   {
  12.     $widget_ops = array('classname' => 'YounesVideoWidget', 'description' => 'Video Widget grabs posts from your video category and the associated thumbnail to display on your sidebar.' );
  13.     $this->WP_Widget('YounesVideoWidget', 'YOUNES: Video Widget', $widget_ops);
  14.   }
  15.  
  16.   function form($instance)
  17.   {
  18.     $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  19.     $title = $instance['title'];
  20. ?>
  21.       <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>
  22.  
  23.       <p>
  24.       <label for="<?php echo $this->get_field_id('category1'); ?>"><?php _e('Category:'); ?></label>
  25.       <select id="<?php echo $this->get_field_id('category1'); ?>" name="<?php echo $this->get_field_name('category1'); ?>" style="width:90%;">
  26.         <option value="0">Choose category:</option>
  27.         <?php
  28.         $cats = get_categories('hide_empty=0');
  29.  
  30.         foreach ($cats as $cat) {
  31.         $option = '<option value="'.$cat->term_id;
  32.         if ($cat->term_id == $instance['category1']) { $option .='" selected="selected';}
  33.         $option .= '">';
  34.         $option .= $cat->cat_name;
  35.         $option .= ' ('.$cat->category_count.')';
  36.         $option .= '</option>';
  37.         echo $option;
  38.         }
  39.       ?>
  40.       </select>
  41.     </p>
  42. <?php
  43.   }
  44.  
  45.   function update($new_instance, $old_instance)
  46.   {
  47.     $instance = $old_instance;
  48.     $instance['title'] = $new_instance['title'];
  49.     return $instance;
  50.   }
  51.  
  52.   function widget($args, $instance)
  53.   {
  54.     extract($args, EXTR_SKIP);
  55.  
  56.     echo $before_widget;
  57.  
  58.     $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
  59.  
  60.     if (!empty($title))
  61.       echo $before_title . $title . $after_title;;
  62.  
  63. /* Widget */
  64. $custom = new WP_Query('posts_per_page=4&cat=13&orderby=date');
  65. if ($custom->have_posts()) :
  66.   echo "<ul>";
  67.   while ($custom->have_posts()) : $custom->the_post();
  68.     echo "<li class='photo'><a href='".get_permalink()."'>";
  69.     echo "<img src='wp-content/themes/tribune2.1.7/images/1.gif' class='play'>";
  70.     the_post_thumbnail($post_id, 'medium');
  71.     echo ShortTitle(get_the_title());
  72.     echo "</a></li>";
  73.   endwhile;
  74.   echo "</ul>";
  75. endif; wp_reset_postdata();
  76.  
  77.     echo $after_widget;
  78.   }
  79.  
  80. }
  81. add_action( 'widgets_init', create_function('', 'return register_widget("YounesVideoWidget");') );
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement