How to display 2 posts from 1 year ago, 2 posts from 2 years ago, etc.
-
Hello! Had trouble searching for this because “1 Year Ago” gives unrelated results.
On my sidebar, I display 3 Recent Posts from 1 Category (I call it the “Setlists” category, from here on) using this code:
<li><h2>3 Recent Radio Setlists</h2>
<ul>
<?php
$posts = get_posts('numberposts=3&category=2');
foreach ($posts as $post) :
setup_postdata($post);
?>
<a href="<?php the_permalink(); ?>"><?php the_excerpt(); ?></a>
<?php
endforeach; ?>
</ul></li>QUESTION HERE — NOW, below that, I want to display 2 Setlists From 1 Year Ago. Then, 2 Setlists From 2 Years Ago. Then, 2 Setlists From 3 Years Ago. And so on. (I wish to go 5 years back.)
How can I do that?
I suppose it would technically be, 2 Setlists From This Same Month But Minus 1 Year. It’s August now, so I want to call up 2 posts from Last August.
Not sure if I need to restart The Loop for each of these calls (years). I have a guess this could be done by modifying this line:
$posts = get_posts('numberposts=3&category=2');
Somehow like,
$posts = get_posts('numberposts=3&category=2&year=-1');'
Perhaps?
- The topic ‘How to display 2 posts from 1 year ago, 2 posts from 2 years ago, etc.’ is closed to new replies.