Title: wrap posts into div
Last modified: August 21, 2016

---

# wrap posts into div

 *  Resolved [mr.cello](https://wordpress.org/support/users/mrcello-1/)
 * (@mrcello-1)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/wrap-posts-into-div/)
 * hello,
    i need to wrap every post i call in the sidebar in a div, so i can style
   better
 * now i have written this code (please dont kill me im a webdesigner)
 *     ```
       <div id="sidebar" class="grid_4 omega">
       	<div id="recent-post-widget">
       		<?php	$the_query = new WP_Query( 'category_name=news'  ); ?>
       		<div class="post-content">
       			<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
       			<?php remove_filter('the_excerpt', 'wpautop'); ?>
       			<?php if( has_post_thumbnail() ) {?>
       			<p class="post-thumb"> <a href="<?php the_permalink(); ?>"> <img class="grid_4 alpha omega" src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>"/> </a> </p>
       			<?php }  ?>
       			<p class="post-date">
       				<?php the_date('j F Y');  ?>
       			</p>
       			<p class="post-title"> <a href="<?php the_permalink(); ?>">
       				<?php the_title();  ?>
       				</a> </p>
       			<p class="post-excerpt">
       				<?php the_excerpt();  ?>
       			</p>
       			<?php endwhile; ?>
       		</div>
       		<?php wp_reset_postdata();?>
       	</div>
       </div>
       ```
   
 * BUT, it wrap all the posts in a single div….
    sorry for the HERESY

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/wrap-posts-into-div/#post-3648832)
 * start the div **after **the line with ‘while()’ and close it **before **the line
   with ‘endwhile’
 *  Thread Starter [mr.cello](https://wordpress.org/support/users/mrcello-1/)
 * (@mrcello-1)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/wrap-posts-into-div/#post-3648834)
 * thankyou my hero 🙂

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

The topic ‘wrap posts into div’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [mr.cello](https://wordpress.org/support/users/mrcello-1/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/wrap-posts-into-div/#post-3648834)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
