-2

I am looking for a way show and navigate wordpress posts by week.

I'll be making 4-6 posts a week and I want the home page to display the posts for that week. Each page before that should display a group of posts sorted by week.

The amount of posts per week is not fixed and will vary so i'm not sure how to go about this.

Thanks in advance!

Dimitra
  • 37
  • 1
  • 5

2 Answers2

0

Something like this is what your after

<?php 
$week = date('W');
$year = date('Y');
$the_query = new WP_Query( 'year=' . $year . '&w=' . $week );
if ( $the_query->have_posts() ) : 
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?> "><?php the_title(); ?></a></h2>
    <?php the_excerpt(); ?>
  <?php endwhile; ?>
  <?php wp_reset_postdata(); ?>
<?php else:  ?>
  <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Dava Gordon
  • 192
  • 2
  • 8
  • thank you so much, that seemed to work great - the only problem is the pagination. how would i go about that? – Dimitra Jun 25 '14 at 20:25
0

Not sure if this will work not tested but here goes

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$week = date('W');
$year = date('Y');
$the_query = new WP_Query( 'posts_per_page' => 50, 'paged' => $paged, 'year=' . $year . '&w=' . $week );
if ( $the_query->have_posts() ) : 
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?> "><?php the_title(); ?></a></h2>
    <?php the_excerpt(); ?>
  <?php endwhile; ?>
  <?php wp_reset_postdata(); ?>
<?php else:  ?>
  <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Dava Gordon
  • 192
  • 2
  • 8
  • I just tried this but now for some reason all the posts are loading on the home page? – Dimitra Jun 25 '14 at 21:20
  • did you change posts_per_page to the number u wanted? – Dava Gordon Jun 25 '14 at 21:26
  • i did that now but the main problem is that i don't know how many posts will be published per week, it will always vary (which is why i wouldn't be able to use a "normal" wordpress loop) – Dimitra Jun 25 '14 at 21:44
  • If you set it to 5 per page then it doesnt matter how many posts you have it will just create a pagination per 5 posts – Dava Gordon Jul 02 '14 at 21:06