Help with the excerpet -.-

Hi guys, I’m trying to modify a widget in order to show image, title and excerpt. I’ve successfull done everything, except for the excerpt ( :P). What I have to do?

Thanks a lot!

[php]<?php

/* Register Widget

  • ---------------------------------------- */
    add_action( ‘widgets_init’, ‘register_top_story’ );

    function register_top_story() {
    register_widget( ‘top_story’ );
    }

/* Widget Class

  • ---------------------------------------- */
    class top_story extends WP_Widget {

    /* Constructor */
    function top_story() {
    	$widget_ops = array( 'classname' => 'top_story', 'description' => 'A widget to display your recent posts and can be sort by category with thumbnail or withour thumbnail.' );
    	$this->WP_Widget( 'top_story', 'DARDANIA Top Story)', $widget_ops);
    	
    }
    
    /* Widget display */
    function widget( $args, $instance ) {
    	extract( $args );
    
    	$post_id = $instance['posts_name'];
    	
    	$title = apply_filters('widget_title', $instance['title']);		
    	if ( empty($title) ) 
    			$title = false;
    
    	echo '<div class="widget top-story">';
    		
    
    	
    
    	
    	if ( $title )
    	echo $before_title . $title . $after_title . "\n"; ?> 
    		<div>
    				
    		<?php $post = get_post( $post_id ); ?>
                            
                            <a href="<?php echo $post->post_name; ?>" class="image"><?php echo get_the_post_thumbnail( $post_id, 'top-story'); ?> </div></span></a>
    		<br />
                         	<div align="center">
                            <p><h6><a href="<?php echo $post->post_name; ?>"><?php echo $post->post_title; ?></h6> </a>   </p>  </div>   
    
    		             
    
    		
    
    
    	
    <?php echo '</div>';
    }
    
    /* Update widget settings */
    function update( $new_instance, $old_instance ) {
    	$instance = $old_instance;
    	$instance['title'] = strip_tags( $new_instance['title'] );
    	$instance['posts_name'] = $new_instance['posts_name'];
    	
    	return $instance;
    }
    
    /* Widget form */
    function form( $instance ) {
    	
    	$defaults = array( 
    		'title' => '',
    		'posts_name' => '',
    	);
    	
    	$instance = wp_parse_args( (array) $instance, $defaults ); ?>
    
    	<p>
    		<label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
    		<input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
    	</p>
        <p>
    	<label for="<?php echo $this->get_field_id('posts_name'); ?>">Choose Post:</label>
    	<select name="<?php echo $this->get_field_name('posts_name'); ?>" id="<?php echo $this->get_field_id('posts_name'); ?>" class="widefat">
            <?php $posts_array = get_posts( array('numberposts'     => -1) ); ?>
    		<?php foreach( $posts_array as $post ) : setup_postdata($post); ?>
    				<option value="<?php echo $post->ID; ?>"<?php selected( $instance['posts_name'], $post->ID ); ?>><?php echo $post->post_title; ?></option>
    		<?php endforeach; ?>
    	</select>
    	</p> 
    	
    	<?php 
    }
    

    }[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service