Advertisement
Guest User

Wordpress Plugin Help

a guest
Mar 27th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. // =============================== Drink Specials Widget ======================================================
  2.  
  3. class drinkSpecials extends WP_Widget {
  4.  
  5.     function drinkSpecials() {
  6.     //Constructor
  7.         $widget_ops = array('classname' => 'drinkSpecials', 'description' => __('List of Drink Specials') );
  8.         $this->WP_Widget('drinkSpecials', __('Drink Specials'), $widget_ops);
  9.     }
  10.    
  11.     function widget($args, $instance) {
  12.     // prints the widget
  13.  
  14.         extract($args, EXTR_SKIP);
  15.        
  16.         echo $before_widget;
  17.         $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
  18.        
  19.      ?>
  20.          <?php
  21.  
  22. $current_day = date('l').'_drinks';
  23.  
  24. // The Query
  25. add_filter('posts_where','yoursite_posts_where',10,2);
  26. query_posts('meta_key='.$current_day.'&orderby=rand&showposts=3');
  27.  
  28.  
  29. echo '<div class="widget">';
  30. echo '<h3 class="clearfix">';
  31. echo '<span class="f1">';
  32. echo 'Today\'s Specials';
  33. echo '</span></h3></div>';
  34.  
  35. echo '<div class="company_info">';
  36.  
  37.  
  38.  
  39. // The Loop
  40. while ( have_posts() ) : the_post();
  41.  echo '<p> <span class="i_drink">';
  42.  echo '<a href=';
  43.  echo get_permalink();
  44.  echo '>';
  45.  echo the_title();
  46.  echo '</a><br>';
  47.  echo 'Special: ';
  48.  echo get_post_meta(get_the_id(), $current_day, $single=true);
  49.  echo '</span> </p>';
  50. endwhile;
  51.  
  52. echo '</div>';
  53. echo '<br><br>';
  54.  
  55.  // Reset Query
  56. remove_filter('posts_where','yoursite_posts_where');
  57. wp_reset_query();
  58.  
  59.         echo $after_widget;
  60.     }
  61.  
  62.     function update($new_instance, $old_instance) {
  63.     //save the widget
  64.         $instance = $old_instance;
  65.         $instance['title'] = strip_tags($new_instance['title']);
  66.         return $instance;
  67.     }
  68.  
  69.     function form($instance)
  70.   {
  71.     $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  72.     $title = $instance['title'];
  73. ?>
  74.   <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>
  75.  
  76. <?php
  77.     }
  78.    
  79.  
  80.  
  81. }
  82.  
  83. register_widget('drinkSpecials');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement