Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Does anyone have a favorite widget for the sidebar that would show the last three posts with:

Title Some of the content... read more

share|improve this question

2 Answers 2

You can create a widget (Create a Widget) like this:

<?php /*
Plugin Name: WDG
Plugin URI: 
Description: Plugin
Version: 0.1
Author URI: 
*/
add_action( 'widgets_init', 'my_wdg' );
function my_wdg() {
    register_widget( 'Wdg' );
}
class Wdg extends WP_Widget {
    function Wdg() {
            /* Settings of widget */
        $widget_ops = array( 'classname' => 'Widget', 'description' => ' Plugin' );

        /* Control settings of widget */
        $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'wdg' );

        /* Create widget */
        $this->WP_Widget( 'wdg', 'Wdg', $widget_ops, $control_ops );
}
    function widget( $args, $instance ) {
    extract( $args );

    /* User-selected settings. */
    $title = apply_filters('widget_title', $instance['title'] );

    /* Before widget (theme defined). */
    echo $before_widget;

    /* Widget title (before e after theme defined). */
    if ( $title )
        echo $before_title . $title . $after_title;
             echo'     <div id="recent">
            <ul>';
             rewind_posts(); 
             query_posts('posts_per_page=3');
                     if ( have_posts() ) : while ( have_posts() ) : the_post();?>
                        <li>
                         <h5><a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
                          <?php the_title();?>
                         </a></h5>
                         <span>
                          <?php the_excerpt ?>
                         </span>
                        </li>
                      <?php endwhile; else: ?>
                      <p>I'm sorry</p>
                    <?php endif; ?>
                   </ul>
                 </div>
           <?php echo $after_widget; }
function update( $new_instance, $old_instance ) {
    $instance = $old_instance;

    /* Strip tags modify qidget configuration. */
      $instance['title'] = strip_tags( $new_instance['title'] );
    return $instance;
}

function form( $instance ) {

    /* default widget setting */
    $defaults = array(              
                    'title' =>  'Recent Comments',
        );
    $instance = wp_parse_args( (array) $instance, $defaults ); ?>
<p>
    <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
        <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
</p>
<?php
    } 
 }  ?>

This widget probably works!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.