HOW-TO #1c: Another bug found in my wp_get_archives modification process and its fix

Thursday, November 20, 2008 15:45
Posted in category PHP, Web Tutorials
  

Anytime when you mess with some sort of code you will most likely always find bugs and errors, unless the code is extremely simple. So here I am again to report another easily fixed bug in my wp_get_archives modification process.

 

The Problem

This “bug” was actually found by Andrew Duck from QuiqCorp (Thanks Andrew!). This one also has to do with the query_posts() function. The code in its current state will not distinguish between the years your posts were published. Let’s say your blog has posts that span over 3 years, from November 2005 to November 2008. In your archives page, the code will output all posts that were published in November under November 2005, November 2006, November 2007, and November 2008. The same is true for all the months.

The Solution 

This fix builds off the bug fix in HOW-TO #1b. Here are the steps:

  1. Go to your wp-includes folder in your site’s file directory
  2. Open general-template.php for editing
  3. Find the wp_get_archives function
  4. Scroll through the function and find the part that you added in (should start with elseif ( ‘month_then_titles’ == $type ) if you followed my directions exactly)
  5. Now scroll down to “the loop”
  6. You should see the line that says 
    query_posts(”monthnum=$arcresult->month&showposts=10000”);
  7. Right before monthnum=$arcresult->month, type in year=$arcresult->year
  8. Now that line should say 
    query_posts(”year=$arcresult->year&monthnum=$arcresult->month&showposts=10000″);

Now your archives page should work like it is supposed to. If any other bugs arise in this process, I’ll for sure post and tell you how to fix them.

After getting all these bugs worked out, I plan on writing an actual WordPress plugin that will make this whole thing a lot easier. Stay tuned!

You can leave a response, or trackback from your own site.

Leave a Reply