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.

No comments yet to

  • This is so helpful to me! I have such trouble messing with Wordpress themes…

  • Thank you a lot for sharing this with all folks you actually recognize what you’re talking about! Bookmarked. Please additionally talk over with my website =). We will have a hyperlink exchange arrangement among us!

  • I not to mention my friends were viewing the best pointers on your web blog and then quickly got a terrible feeling I never expressed respect to you for those strategies. All the men had been so joyful to learn them and have now quite simply been enjoying those things. Thanks for genuinely quite helpful and then for opting for varieties of helpful useful guides most people are really desperate to be informed on. My personal honest apologies for not saying thanks to you sooner.

  • I would like to thank you for the efforts you have put in writing this site. I’m hoping the same high-grade site post from you in the upcoming as well. Actually your creative writing abilities has inspired me to get my own site now. Actually the blogging is spreading its wings fast. Your write up is a good example of it.

  • I don’t even understand how I finished up here, however I assumed this post was great. I do not recognize who you are however definitely you are going to a well-known blogger when you aren’t already ;) Cheers!

  • I’ve been exploring for a little for any high-quality articles or blog posts on this kind of area . Exploring in Yahoo I ultimately stumbled upon this web site. Studying this info So i am happy to convey that I have an incredibly just right uncanny feeling I discovered just what I needed. I so much indubitably will make certain to don’t overlook this site and provides it a glance on a relentless basis.

  • Outstanding article once again! Thumbs up;)