Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: Latest Posts
- * Plugin URI: http://www.template.com/
- * Author: Martin Pultz
- * Author URI: http://www.casensitive.ca/
- * Version: 1.00
- * Description: A plugin template for creating plugins by <a href="http://www.casensitive.ca">CaSenSiTiVe</a>.
- */
- // global variables
- define('CS_LATESTPOSTS_VERSION', 1.0);
- define('CS_LATESTPOSTS_URL', plugin_dir_url( __FILE__ ));
- if (!class_exists("CS_LatestPosts"))
- {
- class CS_LatestPosts extends WP_Widget
- {
- var $widgetOptionsName = "CS_LatestPostsAdminOptions";
- /** constructor */
- function __construct()
- {
- $widget_ops = array( 'description' => 'A widget for displaying the most recent posts.' );
- parent::__construct( 'cs_latest_posts', __('Latest_Posts'), $widget_ops );
- } // end function __construct()
- /** @see WP_Widget::widget */
- function widget( $args, $instance )
- {
- extract( $args );
- $title = apply_filters( 'widget_title', $instance['title'] );
- $subtitle = $instance['subtitle'];
- $show_count = $instance['show_count'];
- echo $before_widget;
- if ( $title )
- echo $before_title . $title . $after_title;
- if( $subtitle )
- echo $before_subtitle . $subtitle . $after_subtitle;
- //wp_get_recent_posts(array('numberposts' => $show_count));
- $args = array( 'numberposts' => $show_count );
- $recent_posts = wp_get_recent_posts( $args );
- echo '<ul>';
- foreach( $recent_posts as $recent )
- {
- echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.$recent["post_title"].'" >' . $recent["post_title"].'</a> </li> ';
- }
- echo '</ul>';
- echo $after_widget;
- } // end function widget()
- /** @see WP_Widget::update */
- function update( $new_instance, $old_instance )
- {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- $instance['subtitle'] = strip_tags($new_instance['subtitle']);
- $instance['show_count'] = $new_instance['show_count'];
- return $instance;
- } // end function update()
- /** @see WP_Widget::form */
- function form( $instance )
- {
- if ( $instance )
- {
- $title = esc_attr( $instance[ 'title' ] );
- $subtitle = esc_attr( $instance[ 'subtitle' ] );
- $show_count = esc_attr( $instance[ 'show_count' ] );
- }
- else
- {
- // default options
- $title = __( 'Latest Posts', 'text_domain' );
- $subtitle = __( 'Techniques, Tips, Stories And More...', 'text_domain' );
- $show_count = __( '5', 'text_domain' );
- }
- ?>
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php echo __('Title:'); ?><br/>
- <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>
- <p><label for="<?php echo $this->get_field_id('subtitle'); ?>"><?php echo __('Subtitle:'); ?><br/>
- <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>
- <p><label for="<?php echo $this->get_field_id('show_count'); ?>"><?php echo __('Number of posts to show:'); ?>
- <select id="<?php echo $this->get_field_id('show_count'); ?>" name="<?php echo $this->get_field_id('show_count'); ?>">
- <? for( $ndx = 1; $ndx <= 10; $ndx++ ) : ?>
- <option value="<?php echo $ndx; ?>" <?php if($show_count==$ndx) echo 'selected' ?> ><?php echo $ndx; ?></option>
- <?php endfor; ?>
- </select></label></p>
- <?php
- } // end function form()
- } // end class CS_LatestPosts
- }
- // register Foo_Widget widget
- add_action( 'widgets_init', create_function( '', 'register_widget("CS_LatestPosts");' ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement