WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For the life of me I can not figure out how to get this widget (built into the theme) to show the excerpt instead of the post content. Can you guys take a look at it for me please. Any help would be greatly appreciated.

// =============================== Latest news posts Widget (particular category) ======================================

class latest_post1 extends WP_Widget {
    function latest_post1() {
        $widget_ops = array('classname' => 'widget Latest News', 'description' => 'List of latest posts in particular category' );
        $this->WP_Widget('latest_post1', 'PT → Latest News', $widget_ops);

    function widget($args, $instance) {
    // prints the widget

        extract($args, EXTR_SKIP);
        echo $before_widget;
        $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
        $category = empty($instance['category']) ? ' ' : apply_filters('widget_category', $instance['category']);
        $post_number = empty($instance['post_number']) ? ' ' : apply_filters('widget_post_number', $instance['post_number']);
        $post_link = empty($instance['post_link']) ? ' ' : apply_filters('widget_post_link', $instance['post_link']);

        // if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
        echo '';

          <?php if($title){?> 
                <h3><?php echo $title; ?></h3>          
                <?php }  ?>

          <div class="latestpost">
                    global $post;
                    $latest_menus = get_posts('numberposts='.$post_number.'postlink='.$post_link.'&category='.$category.'');
                    foreach($latest_menus as $post) :
                 <?php $post_images = bdw_get_images($post->ID,'large');?>

            <div class="post_list">
                <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
                <cite>By <?php the_author_posts_link(); ?></cite>
                <div class="date"> <?php the_time('jS F')  ?></div>

<?php endforeach; ?>

        echo ' </div>';

        echo $after_widget;

    function update($new_instance, $old_instance) {
    //save the widget
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        $instance['category'] = strip_tags($new_instance['category']);
        $instance['post_number'] = strip_tags($new_instance['post_number']);
        $instance['post_link'] = strip_tags($new_instance['post_link']);
        return $instance;


    function form($instance) {
    //widgetform in backend
        $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'category' => '', 'post_number' => '' ) );
        $title = strip_tags($instance['title']);
        $category = strip_tags($instance['category']);
        $post_number = strip_tags($instance['post_number']);
        $post_link = strip_tags($instance['post_link']);

  <label for="<?php echo $this->get_field_id('title'); ?>">Title:
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
  <label for="<?php echo $this->get_field_id('category'); ?>">Categories (<code>IDs</code> separated by commas):
  <input class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" type="text" value="<?php echo attribute_escape($category); ?>" />
  <label for="<?php echo $this->get_field_id('post_number'); ?>">Number of posts:
  <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>" name="<?php echo $this->get_field_name('post_number'); ?>" type="text" value="<?php echo attribute_escape($post_number); ?>" />


share|improve this question

I dont see anywhere on the code that it adds either full text or excerpt. So I decided to test the widget and that's exactly what I got. There is no post content being output.

So my suggestion is to just add

<?php the_excerpt(); ?>

Wherever you want it to output... eg just after the thumb.

<?php $post_images = bdw_get_images($post->ID,'large');?>
<?php the_excerpt(); ?>

I tested it and it worked fine.

share|improve this answer

Your Answer


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.