Advertisement
Guest User

SOUP widget

a guest
Jun 8th, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.40 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: SOUP - Show Off Upcoming Posts
  4. Plugin URI: http://www.doitwithwp.com
  5. Description: Displays your upcoming posts to tease your readers
  6. Author: Dave Clements
  7. Version: 1.1
  8. Author URI: http://www.theukedge.com
  9. */
  10.  
  11. /**
  12.  * Show Off Upcoming Posts Widget Class
  13.  */
  14. class soup_widget extends WP_Widget {
  15.  
  16.  
  17.     /** constructor */
  18.     function soup_widget() {
  19.         parent::WP_Widget(false, $name = 'Upcoming Posts');
  20.     }
  21.  
  22.     /** @see WP_Widget::widget -- do not rename this */
  23.     function widget($args, $instance) {
  24.         extract( $args );
  25.         $title      = apply_filters('widget_title', $instance['title']); // the widget title
  26.         $soupnumber     = $instance['soup_number']; // the number of posts to show
  27.         $shownews   = $instance['show_newsletter']; // whether or not to show the newsletter link
  28.         $newsletterurl  = $instance['newsletter_url']; // URL of newsletter signuip
  29.  
  30.         $args = array(
  31.             'soup_number'   => $soupnumber,
  32.             'show_newsletter'   => $shownews,
  33.             'newsletter_url'    => $newsletterurl
  34.         );
  35.  
  36.         // retrieves upcoming posts from database
  37.         echo $before_widget;
  38.         if ( $title ) { echo $before_title . $title . $after_title; }
  39.             $soupquery = new WP_Query(array('posts_per_page' => $soupnumber, 'nopaging' => 0, 'post_status' => 'future', 'order' => 'ASC'));
  40.             if ($soupquery->have_posts()) {
  41.             while ($soupquery->have_posts()) : $soupquery->the_post();
  42.             $do_not_duplicate = $post->ID;
  43.             ?>
  44.                     <ul>
  45.                             <li>
  46.                                 <?php the_title(); ?>
  47.                             </li>
  48.                     </ul>
  49.             <?php endwhile;
  50.             } ?>
  51.                   </p>
  52.                   <p>
  53.                     <a href="<?php bloginfo('rss2_url'); ?>" title="Subscribe to <?php bloginfo('name'); ?>">
  54.                         <img style="vertical-align:middle; margin:0 10px 0 0;" src="<?php bloginfo('wpurl'); ?>/wp-content/plugins/soup-upcoming-post/icons/rss.png" width="16px" height="16px" alt="Subscribe to <?php bloginfo('name'); ?>" />
  55.                     </a>
  56.                     Don't miss it - <strong><a href="<?php bloginfo('rss2_url'); ?>" title="Subscribe to <?php bloginfo('name'); ?>">Subscribe by RSS.</a></strong>
  57.                   </p>
  58.             <?php if ($shownews)
  59.                 { ?>
  60.                       <p>
  61.                         Or, just <strong><a href="<?php echo $newsletterurl; ?>" title="Subscribe to <?php bloginfo ('name'); ?>">subscribe to the newsletter!</a></strong>
  62.                       </p>
  63.                 <?php } ?>
  64.                 <?php echo $after_widget; ?>
  65.         <?php }
  66.  
  67.     /** @see WP_Widget::update -- do not rename this */
  68.     function update($new_instance, $old_instance) {
  69.         $instance = $old_instance;
  70.         $instance['title'] = strip_tags($new_instance['title']);
  71.         $instance['soup_number'] = strip_tags($new_instance['soup_number']);
  72.         $instance['show_newsletter'] = $new_instance['show_newsletter'];
  73.         $instance['newsletter_url'] = $new_instance['newsletter_url'];
  74.         return $instance;
  75.     }
  76.  
  77.     /** @see WP_Widget::form -- do not rename this */
  78.     function form($instance) {
  79.  
  80.         $title      = esc_attr($instance['title']);
  81.         $soupnumber = esc_attr($instance['soup_number']);
  82.         $shownews   = esc_attr($instance['show_newsletter']);
  83.         $newsletterurl  = esc_attr($instance['newsletter_url']);
  84.         ?>
  85.          <p>
  86.           <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget title:'); ?></label>
  87.           <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; ?>" />
  88.         </p>
  89.     <p>
  90.           <label for="<?php echo $this->get_field_id('soup_number'); ?>"><?php _e('Number of upcoming posts to display'); ?></label>
  91.           <input class="widefat" id="<?php echo $this->get_field_id('soup_number'); ?>" name="<?php echo $this->get_field_name('soup_number'); ?>" type="text" value="<?php echo $soupnumber; ?>" />
  92.         </p>
  93.     <p>
  94.       <label for="show_newsletter"><?php _e('Show Newsletter?'); ?></label>
  95.       <input id="show_newsletter" name="show_newsletter" type="checkbox" class="checkbox" <?php echo $shownews ? 'checked="checked"' : ''; ?> />
  96.     </p>
  97.     <p>
  98.       <label for="<?php echo $this->get_field_id('newsletter_url'); ?>"><?php _e('Newsletter URL:'); ?></label>
  99.       <input class="widefat" id="<?php echo $this->get_field_id('newsletter_url'); ?>" name="<?php echo $this->get_field_name('newsletter_url'); ?>" type="text" value="<?php echo $newsletterurl; ?>" />
  100.     </p>
  101.         <?php
  102.     }
  103.  
  104. } // end class soup_widget
  105. add_action('widgets_init', create_function('', 'return register_widget("soup_widget");'));
  106. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement