Title: Show posts in a widget
Last modified: August 20, 2016

---

# Show posts in a widget

 *  Resolved [tastymouse](https://wordpress.org/support/users/tastymouse/)
 * (@tastymouse)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/show-posts-in-a-widget/)
 * I want to show post of one category in a widget. I use the Executable PHP widget
   to enter the code.
    The code I use is:
 *     ```
       <?php query_posts('cat=16&showposts=3'); ?>
       <?php while (have_posts()) : the_post(); ?>
   
       <ul>
       <li>
                 <?php the_title(); ?>
                 <?php the_content(); ?>
              </li>
       </ul>
       <?php endwhile; ?>
       ```
   
 * _[please remember to mark any posted code – see [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)]_
 * This works BUT other widgets disappear. What am I doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/show-posts-in-a-widget/#post-3291434)
 * try and use WP_Query() and reset the query at the end;
 * example:
 *     ```
       <?php $cat_query = new WP_Query('cat=16&posts_per_page=3'); ?>
       <?php while ($cat_query->have_posts()) : $cat_query->the_post(); ?>
   
       <ul>
       <li>
                 <?php the_title(); ?>
                 <?php the_content(); ?>
              </li>
       </ul>
       <?php endwhile; wp_reset_postdata(); ?>
       ```
   
 * if this does not work, you might need to post a link to your site to illustrate
   the output of your code.
 *  Thread Starter [tastymouse](https://wordpress.org/support/users/tastymouse/)
 * (@tastymouse)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/show-posts-in-a-widget/#post-3291446)
 * yes, that does it!
 * Thanks a lot, Tom
 *  [Ankit Singla](https://wordpress.org/support/users/aksingla/)
 * (@aksingla)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/show-posts-in-a-widget/#post-3291447)
 * You may also want to use in-built recent posts widget from the default Jetpack
   Plugin.
    It can be customized to fit needs.
 * –I have read somewhere that using executable php on pages – compromises security.–

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Show posts in a widget’ is closed to new replies.

## Tags

 * [Executable PHP Widget](https://wordpress.org/support/topic-tag/executable-php-widget/)
 * [sidebar](https://wordpress.org/support/topic-tag/sidebar/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [Ankit Singla](https://wordpress.org/support/users/aksingla/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/show-posts-in-a-widget/#post-3291447)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
