I’d like to create an archive that lists posts under a month header. The months would just be plain text and the post titles, obviously, would link to the posts themselves!
So:
October 2013
- Post title 1
- Post title 2
September 2013
- Post title 1
- Post title 2
August 2013
- Post title 1
- Post title 2
. . . and, if possible, only show one year per page! So, uhhh, I guess it’s paginated too.
Is this possible? Probably. I’ve seen a few threads that deal with similar requests, but nothing quite like this. Or maybe I’m just bad at searching.
Can anyone help me out? Thanks!
Here’s what I found which I’ll break up into pieces:
The
for
loop will loop through how many months we want to pull, which in this case is 12. The$month
variable will hold an integer without any leading zeros that we can use to reference the current (inside loop current) month later. I’m usingstrtotime
to start at 1st day of the current (Real Time) month and count backwards from there. The same thing will happen with$year
We can then use the
$month
variable to query all posts in that month. Then we can go into our normal loop.