WordPress.org

Support

Support » Plugins and Hacks » Archives by Category (UGLY HACK)

Archives by Category (UGLY HACK)

  • I needed the get_archives() function to be able to return posts from only a specific category. I hacked the file template-functions-general.php in the wp-includes directory to be able to do this. This only works if you want your archives to be listed postbypost.
    All i did was change the function get_archives() to add a $cat argument (around line 178), and the query that returns the archive results (around line 264). It should be somewhat simple to change the other queries also so that it works with all archive methods.
    Go to http://phoat.com/downloads/template-functions-general.phps to get it.
    NOTE: This is for WordPress 1.3 alpha (recent nightly). I suppose the hack would be similar for 1.2 also.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Any chance to get this added as a feature, developers?

    Is there a preview somewhere on your site?

    Yeah… sorry I should have posted it. You can find it in action here:
    http://www.bioapplications.gr
    It’s a client’s site. The archives list is in the sidebar under the phone number emulating a recent posts block. It’s in Greek but I’m sure you’ll understand.

    In WP 1.2 I can get it work but it shows all of the posts and not just the posts for one category. So I guess it really doesnt work. Maybe I did something wrong, but I dont think so because it lists the links just it doesnt filter out all of the other categories. Any ideas or do I have to wait for 1.3?

    I’m unable to get it to work as well, although I think it may be the version of MySQL running on the server. I’m getting a big ol’ SQL error right around the ‘WHERE’ in ‘SELECT ID, post_date, post_title, category_id FROM $wpdb->posts, $wpdb->post2cat WHERE $wpdb->post2cat.category_id = $cat AND $wpdb->post2cat.post_id = $wpdb->posts.ID’ (etc.)
    Any thoughts?

    CG-SameCat provides somewhat similar functionality, BTW. That is, showing posts from a given category. Of course, it also can randomize posts, show multiple categories, exclude a particular (say the current) post, etc… Just in case people are looking for same-category listing solutions. 😉
    -d

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Archives by Category (UGLY HACK)’ is closed to new replies.