HOW TO: Display All Your Monthly Archive In One Page

Hi, today I want to talk about archive page. You know, the one that popped when you click on archive link? On normal wordpress themes, archive page will bound to post per page settings you’ve set on admin. However, what if you want to display it all in one page? Maybe because you just write small amout of posts per month that will only take 2 pages and you don’t one your visitor to click next just to see it all?

Don’t worry, I have the solutions. This trick uses query_posts() and wp’s conditional tag. In your archive.php add this code right before THE_LOOP:

if(isset($_GET['m'])){
   $m = $_GET['m'];
   $y = substr($m, 0, 4);
   $m = substr($m, -2);
   $query = "posts_per_page=-1&year=$y&monthnum=$m";
   query_posts($query);
}

Or, if you just have one bing index.php file as template file. Or maybe you use free wordpress blog service on blogsome, you just need to add this code (same as above, before THE_LOOP):

if( is_month() ){
   $m = $_GET['m'];
   $y = substr($m, 0, 4);
   $m = substr($m, -2);
   $query = "posts_per_page=-1&year=$y&monthnum=$m";
   query_posts($query);
}

Code above will reset whatever query happened on that page with our new query defined in $query and fetch the data to be consumed by THE_LOOP. What if you want to show the code to display newest post first? of oldest post first? just append our query with order=ASC to show oldest first and order=DESC to show newest first.

Author: Arief Bayu Purwanto

Hello, my name is Arief Bayu Purwanto, a 24 years old father of a beautiful daughter. Interested in online programming, linux, games, and reading. Currently working on kapanlagi.com as junior developer. I live in a relatively quite and cool place called Malang. I'm available for some freelance stuff as well as some consulting job. You can see my portofolio for some previous task I've finished and some other information related to my capability. Btw, I'm plurking here.