Search

WordPress Plugin: Category/Archive Indexing


By default, WordPress displays categories and archive listings in blog form -- that is, by showing either excerpts or the entirety of the last N posts (dependent upon theme). While this is great for reading, it’s less than wonderful when searching for specific past entries.

Category/Archive Indexing is a WordPress plugin that helps replace the blog style category and archives listings with a list of links to each individual post. It will also work with Simple Tagging Plugin tags.


(Actual look may vary depending on theme)

For a better idea of what this plugin can do, here are some sample pages from this site: a category index, a tag from the tag cloud, and a link from the monthly archive.

To install the plugin:

1) Download the plugin.
2) Upload the plugin to your wp-content/plugins directory.
3) Activate the plugin.

The plugin provides three functions:

function CAI_Header($headerStyleStart='

', $headerStyleEnd='

')

CAI_Header() displays a heading on the page between the $headerStyleStart and $headerStyleEnd elements. In the above picture, it is responsible for the “Category: WordPress” header.

function CAI_SetNumberOfPosts($limit)

CAI_SetNumberOfPosts() determines how many links to show. If you want to show all the links in a category/archive, set it to an arbitrarily large number, such as 99999. If you do not call this function, the default will be however many posts you have set to display on your front page.

function CAI_DisplayLink($beforeLink='', $afterLink='
')

CAI_DisplayLink does the actual displaying of the link itself, and goes inside the_loop. It contains two parameters that you can use to provide customized style elements. $beforeLink can be set to

  • if you would like to display your links as part of an ordered or unordered list.

    Unfortunately, the plugin is not plugin-and-play. To use the plugin, you will need to modify (or create) an archive.php and/or category.php in your theme directory. You can use the following template for both, which will work with many themes:

    
     
    
    

    The div HTML element needs to be altered to match your theme. It tells the browser how to format the list of links. The best way to figure out what to use is to look inside your index.php. The first div you run across is likely to be the one you want. Simply replace the div in the above template with the first div from your index.php and you will probably be good to go.

    For example, the first div found in the wp-andreas01-12 theme index.php is

    . For that theme,
    should be replaced with
    .

    You can also change the CAI function parameters to reflect your tastes.

    Tiga fans, the following zip file contains an archive.php and category.php. Extract them to your wp-content/themes/tiga-06 directory.

    Author’s note: I am not a PHP coder, nor a WordPress expert. This plugin was cobbled together after examining other people’s code and a lot of trial and error. If you have any comments about things I could do better/differently, I’d love to hear it.

    15 comments to WordPress Plugin: Category/Archive Indexing

    • Hey, I just happened to be looking for this plugin over the weekend and it came out today. Thanks! I took your code and got errors, so I played around with it some. Looks like a couple of things were missing. I use a different plugin for the monthly archives, but the categories work great for me now. This is the code that works for me:

    • Ahh, the PHP codes don’t show up right on here. I’ll try again and leave out the beginning
      ?php get_header(); ?>
      ?php get_sidebar(); ?>

      div class=”something>
      ?php CAI_Header(); ?>

      ?php CAI_SetNumberOfPosts(99999); ?>

      ?php while (have_posts()) : the_post(); ?>
      ?php CAI_DisplayLink(); ?>
      ?php endwhile ?>
      /div>

      ?php get_footer(); ?>
      /code>

    • Well, you get the idea! I like the plugin anyway. 🙂

    • Hi Joel -- thanks for the comments. I did miss a couple of php enclosures in the example above, which I have now fixed. Glad to hear you got it working. Let me know if you have any further comments or suggestions.

    • It is not working well. Shouldn’t it just show post related to the category? Why in mine all of the post came up?

    • Hi Iwan -- yes, it should just show the posts related to the category. This plugin does not affect the way the database is queried -- that happens before the category.php or archive.php is even called to do the output. This plugin just provides functionality to change the way the output looks (by outputting hyperlinks instead of actual content). Consequently, it sounds like your problem lies outside of this plugin.

      I wonder if it’s something to do with your specific theme?

    • I get this error

      Parse error: syntax error, unexpected $end in /home/tuscanje/public_html/world-jewels/va/wp-content/themes/unlimited/archive.php on line 64

      after the mod to the archive.php file as described above.

      Thanks!
      G

    • ok never mind. I left too much stuff in the archive.php file

      thanks anyway!

    • Hello!

      It seems that the link property doesn’t work right if Permalinks are enabled.

      http://vip.tuscanjewels.com/category/tuscan_historical_villas_for_sale

      Thanks alot!
      G

    • One of the reliable ones I trust is the ManualDirectorySubmission.in from India. They seem to be much better than the rest.

    • Hello; I was able to manage getting the plugin to work; however, on my website it seems that when I click to see the directory, I’m missing my left sidebar.

      Also I was wondering if there was any way for this plugin to list child categories. before posting articles.

    • I did not understand how to change and what to change. I changed to function CAI_SetNumberOfPosts(99999)

      but it shows
      Parse error: syntax error, unexpected T_LNUMBER, expecting ‘&’ or T_VARIABLE in /home/pisqacom/public_html/wp-content/plugins/CatArcIndexing.php on line 38

      I dont have much knowledge of editing and these scripts… so can you please prepare a simple php file which i can simply upload that file and activate… and it shows all article links or list when i click on category or archive.. Please help

    • AlvinCampbell

      good post

    Leave a Comment

    Put C++ code inside [code][/code] tags to use the syntax highlighter