WordPress.org

Ready to get started?Download WordPress

Forums

Archives by Category (UGLY HACK) (7 posts)

  1. Anonymous
    Unregistered
    Posted 10 years ago #

    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.

  2. Anonymous
    Unregistered
    Posted 10 years ago #

    Any chance to get this added as a feature, developers?

  3. MathiasBynens
    Member
    Posted 10 years ago #

    Is there a preview somewhere on your site?

  4. Anonymous
    Unregistered
    Posted 10 years ago #

    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.

  5. perfectionisboring
    Member
    Posted 10 years ago #

    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?

  6. pixellated
    Member
    Posted 9 years ago #

    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?

  7. davidchait
    Member
    Posted 9 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags