- Learn C++ - https://www.learncpp.com -

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 [1] 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 [2], a tag from the tag cloud [3], and a link from the monthly archive [4].

To install the plugin:

1) Download the plugin [5].
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 [6]. 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.