Herself’s Webtools

Webtools for Webmasters: Scripts, HowTos, Templates, Plugins, Widgets, Tips and Useful Information

Herself’s Webtools header image 1

Here is a plugin to print a list of all your posts by category in Wordpress

October 1st, 2007 · 12 Comments

Over time all your posts get buried. If someone visits your blog can that person easily find a post she is looking for? Can someone find a post related to one he is viewing? Wordpress archive pages give you a list of categories and a list of months but no direct links to your posts. You know what they say, 3 clicks and your visitor is gone.

So I wanted an archive that listed all my posts, by category, alphabetically by title. So I started with Frucomerci’s ‘List Posts by Category Plugin for Wordpress and shamelessly hacked his plugin.

The new plugin ArchiveByCategory lists all your published blog posts by category alphabetically.

Download, unzip, upload to your plugin directory and active the plugin.

Oct 17th —————————————————————————–

Ok I’ve been told you’all don’t like hacking your templates. So you can just create a post or page; click the ‘code’ button an add the following line

<!– archivesbycategory –>

Braver folks can follow directions below to hack your template

* thank Rob at Backyard Chickens for letting me know you wanted this.

—————————————————————————————-

Now an archive page is needed. Next you need to hack your template. Open up ‘archives.php’ [ not archive.php ] and find the line

<?php wp_list_categories(’title=0′); ?>

Yours might be slightly different. Remove that line and put in its place:

<?php echo archives_by_category(); ?>

Now all you have to do is create a page - call it ‘Archives’ and select ‘Archives’ as the page template. Nothing else needs to be done but to ‘publish’ the page.

I’ve built in anchor links to the page. It will get very long over time. You will want to create anchor links to each category. ( See How and why you should use anchor links ).

The archives page will update itself with all your news posts as you publish them. Nothing more need be done once this has been set up.

[ check sidebar for newest versions ]
*If you are using Wordpress 2.3 download the ArchivesByCategory V 2.2 I totally cleaned up the MySQL and php and it is easier to read, for you to configure and should run a little faster.

*If you are using an earlier Wordpress version you need ArchivesByCategory V 1.0

If you just want to list one category of posts see:
Plugin to list one category of posts ( WP < 2.3 )
Plugin to create a list of posts for one category ( WP>2.3 )

Tags: archives · hack your template · how to · wordpress · wordpress template

12 responses so far ↓

  • 1 Kristin // Oct 2, 2007 at 5:04 am

    I’m not able to make this work in WP 2.3, - as far as I can see is that this line causes all the troubles:
    $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (Select post_id FROM $wpdb->post2cat WHERE category_id =$posts->cat_ID) ORDER BY post_title ASC"); as it uses the old db tables to WP, but I’m not mySQL guru so I’m not sure where to go to fix it.

    And I also get an error on blogs where I don’t use the prefix wp_ : however I found that replacing wp_ with $$wpdb-> did the trick.

  • 2 admin // Oct 2, 2007 at 10:03 am

    Thank you. I am stuck at the ER with dh. I will fix this and post an update after I get home and catch some sleep. Look for it around dinner or early evening.

  • 3 admin // Oct 2, 2007 at 1:34 pm

    OK, I have V2.1 here, link on side bar. I’ve uploaded it to the WP plugin repository as well.

    V2.1 will handle tables that do not begin with the default wp_

    Also somehow the file V2.0 overwrote or got mixed up with V1.0 a clean version is on the side bar. That line does not belong in version 2.0

    The clean version is up at the WordPress plugins site as well. All should be well.

    It is going to be a hectic week here. If you have any questions or troubles, post a note here and I’ll get to it as soon as I can

  • 4 Kristin // Oct 8, 2007 at 2:47 am

    Sorry, I didn’t get back right away, seems like I have a busy week myself..
    Anyway, your new version (2.1) worked, I just had to insert one line to make sure only categories (and not tags) was shown - right over and post_status = 'publish':

    and taxonomy = 'category'

    And I just want to thank your for a great plugin :)

  • 5 admin // Oct 8, 2007 at 10:00 am

    Thank you!

    I have 2.3 on my home machine but have some more plugins to write before I convert my online blogs. So I haven’t any tags and totally missed that.

    I’ll fix that, probably Wed., sooner if time allows. I’m hoping to get the rest of what I need written this week and upgrade the blogs next weekend.

  • 6 admin // Oct 10, 2007 at 12:23 pm

    OK Version 2.2 will not show tags, just categories. I made the changes you suggested and they worked beautifully.

    I’m having trouble with svn but as soon as I figure that out it’ll be at WP plugin repository. In the meantime you can download it from the left sidebar link.

  • 7 admin // Oct 17, 2007 at 12:34 pm

    As suggested to me both versions have been updated so you can just add
    to a page or post ( in the code section) rather than hack your template.

    I should have the new versions uploaded to WP after a brief battle with Subversion.

  • 8 teacherparentresources // Mar 7, 2008 at 8:42 am

    Is it possible to remove one of the categories from the list?

  • 9 herself // Mar 7, 2008 at 9:22 am

    No, and I needed that also. So I wrote a plugin that lets you list each category separately. You can use it to build archive pages or list each category in a side bar. I’m using it on my recipe page. Instructions and download are here

  • 10 doesje // May 30, 2008 at 4:08 am

    Thanks, this plugin seems just exactly what i need. However, i can’t figure out your instruction to ‘Now all you have to do is create a page - call it ‘Archives’ and select ‘Archives’ as the page template.’

    How can i select ‘Archives’ as a page template?

    I have the feeling that this might be very simple, so sorry if this is a stoopid question… :)

  • 11 doesje // May 30, 2008 at 5:27 am

    Ok, found it. ‘NOTE: In order to access the Page Template selector, there must be at least one custom Page Template available in the active theme’.

    Grrr.

  • 12 ljmacphee // May 30, 2008 at 8:13 am

    Ouch, sorry about that, I guess I had always by sheer dumb luck had some in there.

    Thanks for letting people know.

You must log in to post a comment.