Support » Fixing WordPress » Order posts by week

  • Resolved phahreed



    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.


Viewing 1 replies (of 1 total)
  • 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()): ?>
    <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>
    <?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.