title: Edit My Recent Post Widget
body: <p>I have a Wordpress theme that I bought, many different widgets come with it.
  I have one with the following code and, what it does is that shows the Recent Posts.
  I need to make a change in it, actually two, instead of showing me the recent POST I need it to show me the recent portfolio items and only of a certain category.</p>
  
  <pre><code>&lt;?php
  // =============================== My Recent Posts (News widget) ======================================
  class MY_PostWidget extends WP_Widget {
      /** constructor */
      function MY_PostWidget() {
          parent::WP_Widget(false, $name = 'My - Recent Posts');  
      }
  
    /** @see WP_Widget::widget */
      function widget($args, $instance) {     
          extract( $args );
          $title = apply_filters('widget_title', $instance['title']);
                  $category = apply_filters('widget_category', $instance['category']);
                  $linktext = apply_filters('widget_linktext', $instance['linktext']);
                  $linkurl = apply_filters('widget_linkurl', $instance['linkurl']);
                  $count = apply_filters('widget_count', $instance['count']);
          ?&gt;
                &lt;?php echo $before_widget; ?&gt;
                    &lt;?php if ( $title )
                          echo $before_title . $title . $after_title; ?&gt;
  
                          &lt;?php  $temp = $wp_query;
                                       $wp_query= null;
                                       $wp_query = new WP_Query();  ?&gt;
  
                                  &lt;ul class="latestpost"&gt;
  
                                  &lt;?php $querycat = $category; ?&gt;
  
                                  &lt;?php $wp_query-&gt;query("showposts=". $count ."&amp;category_name=". $querycat); ?&gt;
  
                                  &lt;?php if ($wp_query-&gt;have_posts()) : while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post();?&gt;
                                  &lt;li&gt;
                      &lt;?php if(has_post_thumbnail()) {
                              echo '&lt;figure class="featured-thumbnail"&gt;&lt;a href="'; the_permalink(); echo '"&gt;';
                              echo the_post_thumbnail('small-post-thumbnail');
                              echo '&lt;/a&gt;&lt;/figure&gt;';
                              }
                            ?&gt;
                    &lt;time datetime="&lt;?php the_time('Y-m-d\TH:i'); ?&gt;"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_time('[m-d-Y]'); ?&gt;&lt;/a&gt;&lt;/time&gt;
                    &lt;?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,13);?&gt;
                                  &lt;/li&gt;
                                  &lt;?php endwhile; ?&gt;
                                  &lt;/ul&gt;
                                  &lt;?php endif; ?&gt;
  
                                  &lt;?php $wp_query = null; $wp_query = $temp;?&gt;
  
  
                                  &lt;!-- Link under post cycle --&gt;
                                  &lt;?php if($linkurl !=""){?&gt;
                                      &lt;a href="&lt;?php echo $linkurl; ?&gt;" class="button"&gt;&lt;?php echo $linktext; ?&gt;&lt;/a&gt;
                                  &lt;?php } ?&gt;
  
  
                &lt;?php echo $after_widget; ?&gt;
  
          &lt;?php
      }
  
      /** @see WP_Widget::update */
      function update($new_instance, $old_instance) {             
          return $new_instance;
      }
  
      /** @see WP_Widget::form */
      function form($instance) {              
        $title = esc_attr($instance['title']);
              $category = esc_attr($instance['category']);
              $linktext = esc_attr($instance['linktext']);
              $linkurl = esc_attr($instance['linkurl']);
              $count = esc_attr($instance['count']);
          ?&gt;
        &lt;p&gt;&lt;label for="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;"&gt;&lt;?php _e('Title:', 'theme1472'); ?&gt; &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('title'); ?&gt;" type="text" value="&lt;?php echo $title; ?&gt;" /&gt;&lt;/label&gt;&lt;/p&gt;
  
        &lt;p&gt;&lt;label for="&lt;?php echo $this-&gt;get_field_id('category'); ?&gt;"&gt;&lt;?php _e('Category Slug:', 'theme1472'); ?&gt; &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('category'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('category'); ?&gt;" type="text" value="&lt;?php echo $category; ?&gt;" /&gt;&lt;/label&gt;&lt;/p&gt;
  
        &lt;p&gt;&lt;label for="&lt;?php echo $this-&gt;get_field_id('count'); ?&gt;"&gt;&lt;?php _e('Posts per page:'); ?&gt;&lt;input class="widefat" style="width:30px; display:block; text-align:center" id="&lt;?php echo $this-&gt;get_field_id('count'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('count'); ?&gt;" type="text" value="&lt;?php echo $count; ?&gt;" /&gt;&lt;/label&gt;&lt;/p&gt;
  
               &lt;p&gt;&lt;label for="&lt;?php echo $this-&gt;get_field_id('linktext'); ?&gt;"&gt;&lt;?php _e('Link Text:', 'theme1472'); ?&gt; &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('linktext'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('linktext'); ?&gt;" type="text" value="&lt;?php echo $linktext; ?&gt;" /&gt;&lt;/label&gt;&lt;/p&gt;
  
               &lt;p&gt;&lt;label for="&lt;?php echo $this-&gt;get_field_id('linkurl'); ?&gt;"&gt;&lt;?php _e('Link Url:', 'theme1472'); ?&gt; &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('linkurl'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('linkurl'); ?&gt;" type="text" value="&lt;?php echo $linkurl; ?&gt;" /&gt;&lt;/label&gt;&lt;/p&gt;
          &lt;?php 
      }
  
  } // class  Widget
  ?&gt;
  </code></pre>
  
  <p>This is how it looks like now in the widget pane:</p>
  
  <p><img src="https://i.stack.imgur.com/TDhhB.png" alt="Widget"></p>