Advertisement
Guest User

Untitled

a guest
Jan 13th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.77 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: Latest Posts
  4.  * Plugin URI: http://www.template.com/
  5.  * Author: Martin Pultz
  6.  * Author URI: http://www.casensitive.ca/
  7.  * Version: 1.00
  8.  * Description: A plugin template for creating plugins by <a href="http://www.casensitive.ca">CaSenSiTiVe</a>.
  9.  */
  10.  
  11. // global variables
  12. define('CS_LATESTPOSTS_VERSION', 1.0);
  13. define('CS_LATESTPOSTS_URL', plugin_dir_url( __FILE__ ));
  14.    
  15. if (!class_exists("CS_LatestPosts"))
  16. {
  17.     class CS_LatestPosts extends WP_Widget
  18.     {
  19.         var $widgetOptionsName = "CS_LatestPostsAdminOptions";
  20.        
  21.         /** constructor */
  22.         function __construct()
  23.         {
  24.             $widget_ops =  array( 'description' => 'A widget for displaying the most recent posts.' );
  25.             parent::__construct( 'cs_latest_posts', __('Latest_Posts'), $widget_ops );
  26.         } // end function __construct()
  27.    
  28.         /** @see WP_Widget::widget */
  29.         function widget( $args, $instance )
  30.         {
  31.             extract( $args );
  32.            
  33.             $title = apply_filters( 'widget_title', $instance['title'] );
  34.             $subtitle = $instance['subtitle'];
  35.             $show_count = $instance['show_count'];
  36.            
  37.             echo $before_widget;
  38.             if ( $title )
  39.                 echo $before_title . $title . $after_title;
  40.            
  41.             if( $subtitle )
  42.                 echo $before_subtitle . $subtitle . $after_subtitle;
  43.                
  44.             //wp_get_recent_posts(array('numberposts' => $show_count));
  45.             $args = array( 'numberposts' => $show_count );
  46.             $recent_posts = wp_get_recent_posts( $args );
  47.             echo '<ul>';
  48.             foreach( $recent_posts as $recent )
  49.             {
  50.                 echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.$recent["post_title"].'" >' .   $recent["post_title"].'</a> </li> ';
  51.             }
  52.             echo '</ul>';
  53.             echo $after_widget;
  54.         } // end function widget()
  55.    
  56.         /** @see WP_Widget::update */
  57.         function update( $new_instance, $old_instance )
  58.         {
  59.             $instance = $old_instance;
  60.             $instance['title'] = strip_tags($new_instance['title']);
  61.             $instance['subtitle'] = strip_tags($new_instance['subtitle']);
  62.             $instance['show_count'] = $new_instance['show_count'];
  63.            
  64.             return $instance;
  65.         } // end function update()
  66.    
  67.         /** @see WP_Widget::form */
  68.         function form( $instance )
  69.         {
  70.             if ( $instance )
  71.             {
  72.                 $title = esc_attr( $instance[ 'title' ] );
  73.                 $subtitle = esc_attr( $instance[ 'subtitle' ] );
  74.                 $show_count = esc_attr( $instance[ 'show_count' ] );
  75.             }
  76.             else
  77.             {
  78.                 // default options
  79.                 $title = __( 'Latest Posts', 'text_domain' );
  80.                 $subtitle = __( 'Techniques, Tips, Stories And More...', 'text_domain' );
  81.                 $show_count = __( '5', 'text_domain' );
  82.             }
  83.             ?>
  84.             <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php echo __('Title:'); ?><br/>
  85.             <input style="width: 220px;" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" disabled /></label></p>   
  86.                    
  87.             <p><label for="<?php echo $this->get_field_id('subtitle'); ?>"><?php echo __('Subtitle:'); ?><br/>
  88.             <input style="width: 220px;" id="<?php echo $this->get_field_id('subtitle'); ?>" name="<?php echo $this->get_field_id('subtitle'); ?>" type="text" value="<?php echo $subtitle; ?>" disabled /></label></p>
  89.            
  90.             <p><label for="<?php echo $this->get_field_id('show_count'); ?>"><?php echo __('Number of posts to show:'); ?>
  91.             <select id="<?php echo $this->get_field_id('show_count'); ?>" name="<?php echo $this->get_field_id('show_count'); ?>">
  92.               <? for( $ndx = 1; $ndx <= 10; $ndx++ ) : ?>
  93.                 <option value="<?php echo $ndx; ?>" <?php if($show_count==$ndx) echo 'selected' ?> ><?php echo $ndx; ?></option>
  94.               <?php endfor; ?>
  95.             </select></label></p>
  96.             <?php
  97.         } // end function form()
  98.     } // end class CS_LatestPosts
  99. }
  100.  
  101. // register Foo_Widget widget
  102. add_action( 'widgets_init', create_function( '', 'register_widget("CS_LatestPosts");' ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement