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='<h2>', $headerStyleEnd='</h2>')

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='<br>')

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 <li> 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:

<?php get_header(); ?>
<?php get_sidebar(); ?> <!-- Remove this line if it causes an error -->

<div class="something"> <!-- Replace this div to match your theme -->
<?php CAI_Header(); ?>

<?php CAI_SetNumberOfPosts(99999); ?>

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

<?php get_footer(); ?>

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 <div id="content">. For that theme, <div class="something"> should be replaced with <div id="content">.

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.

guest
Your email address will not be displayed
Find a mistake? Leave a comment above!
Correction-related comments will be deleted after processing to help reduce clutter. Thanks for helping to make the site better for everyone!
Avatars from https://gravatar.com/ are connected to your provided email address.
Notify me about replies:  
15 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments