Title: Order posts by week
Last modified: August 21, 2016

---

# Order posts by week

 *  Resolved [phahreed](https://wordpress.org/support/users/phahreed/)
 * (@phahreed)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/order-posts-by-week/)
 * Hi,
 * I am currently making a theme for a new magazine. We post four new articles every
   week on Monday. I would like to be able to order all of the posts from that week
   under a single heading of that Monday’s date.
 * I’m having trouble looping through only one week’s worth of articles, adding 
   a breaker – which says the date of the next week – and then looping through the
   next week’s articles, ad infinitum.
 * How would I go about doing this? I don’t really want to add a new category for
   every week, as all of the articles are published on the same date.
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Thread Starter [phahreed](https://wordpress.org/support/users/phahreed/)
 * (@phahreed)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/order-posts-by-week/#post-3823382)
 * I figured out a way of doing it by comparing the_date() of each article to the
   previous one and either creating a new group or not depending on the outcome.
   No need to edit the Loop at all! 🙂
 *     ```
       <?php $prevDate=get_the_date();	?>
       <?php while ($prevDate==get_the_date()): ?>
       <li>
       <div class="article-thumb"><a href="<?php the_permalink() ?>"> <?php the_post_thumbnail(); ?> </a></div>
       <div class="article-title"><a href="<?php the_permalink() ?>"><?php the_title() ?></a></div>
       <div class="byline"><?php the_author_posts_link(); ?></div>
       <div class="kicker"> <?php the_excerpt(); ?> </div>
       </li>
       <?php $prevDate=get_the_date();	?>
   
       <?php the_post(); ?>
       <?php endwhile; ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Order posts by week’ is closed to new replies.

## Tags

 * [date](https://wordpress.org/support/topic-tag/date/)
 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [phahreed](https://wordpress.org/support/users/phahreed/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/order-posts-by-week/#post-3823382)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
