Using Filters

Filters are a way for AZIndex users with some knowledge of PHP programming to tailor the appearance and/or behavior of their indexes.  For example, suppose you don’t like the appearance of the alphabetical links at the top of the index, and you can’t get it to look the way you want it to look by using a customized CSS stylesheet.  Normally you would be stuck with what you have, but with AZIndex you can use the azindex_alpha_links filter to get in there and tinker with the HTML for the index before it is displayed on the webpage.

Of course, you have to write a function with some PHP code in it to do that, so this is not for every AZIndex user, but if you’re an expert PHP hacker, these are the steps you can follow:

  1. Find a good place to put your new PHP code.  I prefer creating my own little plugin for all my tailoring needs, since there is no chance of it being overwritten when upgrading, but you could add it to somewhere like functions.php inside your theme directory.
  2. Add the following line to your code (not inside any function):
    add_filter('azindex_alpha_links', 'my_alpha_links_filter');
  3. Just below that, add a new function called my_alpha_links_filter.
    function my_alpha_links_filter($output) {
        /* My HTML modification code here */
        return $output;
    }

    Now all you have to do is write the code to modify the HTML in $output to make the alpha-links look the way you want them to look. (Well, yes, that’s the hard part, but you get the idea!)

If you would rather throw away the generated HTML and start again, you can add extra parameters to the filter function which will contain all you need to build set of alphabetical links in the style of your choosing:

  1. First you have to modify the add_filter function call:
    add_filter('azindex_alpha_links', 'my_alpha_links_filter', 10, 5);

    where 10 is the default priority of the filter (we don’t use it, but it has to be present in the call) and 5 is the number of parameters AZIndex will pass to your filter function.

  2. You also have to modify the filter function to access the extra variables being passed to you:
    function my_item_filter($output, $idindex, $links, $pagelink, $currentpage) {
        /* My HTML modifying code here */
        return $output;
    }

    where $idindex is the id of the index being displayed (in case you just want to modify one index out of many), $links is an array of the characters in the links and the page in the index they link to, and so on.

    Note: If you only need to know the id of the index, then you can set the number of parameters to 2 in the add_filters call.

Now that you know everything there is to know about using filters (well, not really, but it’s enough!), you can look up the details of each AZIndex filter in the following reference pages.

Continue to the next page »