WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Order posts by week (2 posts)

  1. phahreed
    Member
    Posted 10 months ago #

    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!

  2. phahreed
    Member
    Posted 10 months ago #

    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; ?>

Reply

You must log in to post.

About this Topic