Display Item Filter
The display item filter is called just before an item is inserted into an index page. Using this filter allows you to affect the what shows up on the web page when this item is displayed. Note, you cannot use this filter to influence the sorting of the index. That is what the item filter is for.
Note: this filter will only be called if the Group items with the same heading… option is not selected.
To add a filter for all indexes in your blog use the following code:
add_filter('azindex_display_item', 'my_display_item_filter');
Then add the display item filter function with the name you specified:
function my_display_item_filter($item) {
/* My item modifying code here */
return $item;
}
The $item parameter is an associative array containing all the information about the item being loaded into the index. It has the following keys names:
| Key Name | Description | |||
|---|---|---|---|---|
| id | Post id - the id of the post linked to by this item | |||
| head | The item’s heading string, as it will be displayed in the index | |||
| subhead | The item’s subheading string, as it will be displayed in the index | |||
| desc | The item’s description string, as it will be displayed in the index | |||
| sort-head | The item’s sorted heading string – used only when sorting the index | |||
| sort-subhead | The item’s sorted subheading string – used only when sorting the index | |||
| sort-desc | The item’s sorted description string – used only when sorting the index | |||
| key | Category/tag id of the item – only if category/tag is selected as the heading | |||
| output | Empty when the filter function is called, but if you add your own HTML here, then it will be used for displaying the item. | |||
The important values for this filter are:
- head, subhead, and desc, which you can modify to change the content of the item display
- id, which you can use in WordPress functions to query the information you need about the object
- output, which you can use if you want to completely replace the HTML used for the item. See below for more information
Note: modifying the other values in the array does not affect anything.
You can change the output in two different ways:
- by modifying the head, subhead, and desc values individually. Each value will be wrapped in a <span> element before being output. You can insert any HTML you like into the values, including <img> tags for thumbnails. The permalink for the item will be added to the item by the plugin after the filter returns. If you don’t want the default ‘-‘ character between the head and subhead just type a space character into the Heading separator field in the settings page.
- by putting HTML to the output value. If you add anything at all to output then it will be used instead of the usual output generated by the plugin. You can use this field to create index items with exactly the look and feel you need, but remember, you will be responsible for adding the link to the post to the HTML, otherwise there will be nowhere for readers to click to get to your posts. The item will be wrapped in a list item tag <li> when it is added to the index page,
If you use this filter to alter the way the items are displayed, you may well need to modify the default CSS stylesheet used by your index. In the settings page, simply select the following option:
- Use customized stylesheets for the index
and you can make the changes you need. The filter always uses the first set of CSS styles on the settings page, the one labeled Stylesheet for ungrouped index items.
Note: Remember, if you are using the output value to return your own HTML, the .head, .subhead, and .desc CSS classes will not be used unless you use them in your HTML.
More Display Item Filter Parameters
If you only want to use the item filter with one specific index, you need to know the id of the index your filter function is being called for. You can do this by specifying that you want your filter to receive all the available parameters, which is 2:
add_filter('azindex_display_item', 'my_item_filter', 10, 2);
Note: the third parameter in the add_filter() call, 10, is the default filter priority, and must be present so you can specify the number of parameters you want to be passed to your filter.
Now you can modify the filter function to receive the index id, so you can add a test in your code to see if you need to filter this item.
function my_display_item_filter($item, $idindex) {
if ($idindex = INDEX_ID) {
/* My item modifying code here */
}
return $item;
}
Note: in future versions for AZIndex, $idindex may be a string, as well as a number.
Example: Movie Stars Thumbnail Index
As an example of what you can do with this filter, this is how I created the thumbnail index of movie stars in the gallery section:
- Find a place to put a small amount of PHP code—I prefer to put it in another plugin (one I made myself) but you can also add it to somewhere like your functions.php file in your current theme’s directory.
- Add the following code to your PHP file:
/* This call hooks the filter function into the plugin. Since * I only want to modify the content of one of my indexes, I * specify that I need both available parameters passed * to my filter function. */ add_filter('azindex_display_item', 'my_add_thumb', 10, 2); /** * This is the filter function. It simply puts the post's thumbnail into * the head field and moves the original contents of the head field * (the title of the post) into the subhead field. * * @param $item array contains information about the item to be displayed * @param $idindex the id of the index being displayed */ function my_add_thumb($item, $idindex) { // Only use this filter to process one specific index. if ($idindex == 18) { // I stored the thumbnail for each post in a custom value called "Thumb" // If you are using a thumbnail plugin, you will need to replace this line // with the correct function to obtain the URL of the thumbnail image. // (Note: you're on your own with that!) $thumb = get_post_custom_values('Thumb', $item['id']); // Move the title of the post from the heading to the subheading. // I wrap the text inside a "div" element so that I can control exactly // where the text appears next to the thumbnail. You may not have // to do this, depending on what you need. $item['subhead'] = '<div style="height:50px;padding-top:30px;">'.$item['head'].'</div>'; // Wrap the thumbnail image inside an "img" tag and put it in the heading. $item['head'] = "<img src='{$thumb[0]}'/>"; } // Return the modified item back to the plugin. return $item; }Please be aware that this code will not work as-is on your blog. You will need to make changes to use the correct index id, to fetch the correct thumbnail URL, and to adjust the positioning of the image and text, to get the index looking the way you want.
- In the index settings:
- Make sure the Group items with the same heading… option is not selected
- Select the Use customized stylesheets for the index option
- Make the following change to the first line of the Stylesheet for ungrouped index items:
.azindex .head {float:left;padding-right:10px}As mentioned above, the stylesheet changes required depend on the output you are generating for the item.
- Save the settings and the file with the filter code, and go have a look at your new index.
Additional Notes
There are some other things to be aware of when you are using a display item filter:
- If you are only interested in altering the appearance of the index items (and not the way the index is sorted), then use this filter over the azindex_item filter as it will be faster, since it will be called much less often.
- The filter will not be called if you have the Group headings… option set, so the grouping capabilities of the plugin will not be available when you use this filter.
- The strings in head, subhead, and desc use the UTF-8 encoding, where some characters (like those unique to certain languages) are more than one byte long. If you are going to manipulate text that contains these multi-byte characters, you should use the PHP multi-byte string library functions to do so.
- Unless you have a good reason, it’s best not to use the contents of sort-head, sort-subhead, or sort-desc in this filter.
- Other keys may be added to the $item array in future releases, so the number of keys and their order may change over time.
ayahuasca glimpse said:
Thank you very much for your site. It is very important to me. Thank you.
movers South Florida said:
Hi there, I discovered your blog via Google even as looking for a related topic, your web site got here up, it looks great. I’ve bookmarked it in my google bookmarks.
Bobby Herout said:
betting bonus at bettingbonuses.biz
Sacramento Plumbing said:
Hey i think your blog is fantastic! I found it on Google. I think i will come back one day soon.
British shopping cashback said:
What’s Going down i’m new to this, I stumbled upon this I have discovered It positively helpful and it has aided me out loads. I hope to give a contribution & help other users like its helped me. Great job.
Augustus Sulima said:
I’m right there with you, although I would read anything she writes, the cover is definitely intruiging!
Darnell Bearup said:
You know that anything goes once you pick up a work by the zany and terrific Kurt Vonnegut. The man knows how to dish up satire like none other. He’ll spew out his complaints about the government, the world, people, etc., and instead of making it sound like a bunch of inane ranting he uses all of that to create a crazy world filled with outrageous characters and situations. “Breakfast of Champions” is an off-the-wall novel that is about 300 pages of pure hilarity and comedic chaos. Some of the most outrageous characters lie within this masterpiece.Listen: This story revolves mainly around two characters. There’s Kilgore Trout who is an aging and bitter sci-fi writer that nobody has ever heard of (except for one person). His stories have only appeared in very adult magazines. So naturally, he has “doodley-squat” to show for it. The other person that this story is about is a car dealer by the name of Dwayne Hoover, a man that everyone in town considers a “fabulously well-to-do” person. Dwayne is losing his mind and is ever so gracefully slipping into the cozy and wonderful world of insanity. What pushes him over the edge will take place when the two meet and Hoover takes one of Trout’s literary works as reality. The results are unforgettable and hilariously disturbing in this dark and offbeat tale of the flawed human beings who are destroying Mother Earth.
Katharina Hedeen said:
Wow good info, thank you. This is what i looking for.
Lawrence said:
More like: The cost of implementing “”"proper”"” security against unmitigated and unreasonable to expect attacks outweigh the benefits, when out contacts will indemnify us anyway. You know why they don’t bother? One, they expect that a person won’t be able to access the equipment without being caught, or won’t risk breaking and entering or other criminal charges to get at best, free laundry. Minimal payout = less incentive to attack, less reason to care.
Erline said:
Interesting….
How did you get the image inside the QR?
This is all new to me, so I have been googling and reading up as much as possible…
Glattleder Pflege said:
Howdy. Very cool website!! Guy .. Beautiful .. Wonderful .. I’ll bookmark your site and take the feeds also…I’m happy to locate numerous helpful info here within the post. Thank you for sharing.
California small claims said:
I’ve been exploring for a little bit for any high quality articles or blog posts in this sort of space . Exploring in Yahoo I at last stumbled upon this website. Reading this info So i am satisfied to exhibit that I’ve an incredibly good uncanny feeling I found out exactly what I needed. I so much unquestionably will make certain to do not disregard this website and give it a glance regularly.
proffesional cleaning chemicals said:
I was just looking for this info for a while. After 6 hours of continuous Googleing, finally I got it in your site. I wonder what’s the lack of Google strategy that do not rank this kind of informative web sites in top of the list. Generally the top web sites are full of garbage.
Tanmoy said:
I want to display list of post in category page using AZindex. So I’ve created a category template. Now I need help to display posts list by category there. For instance, when I’ll go to domain.com/category/health, the page should display only post list from health category using azindex. Is it possible? I need your help.
riding boot said:
I’ve recently started a web site, the info you offer on this site has helped me greatly. Thanks for all of your time & work.
Sarai said:
I am love this . but can u tell me how to remove points front of the main latter …. Plz visit this link http://www.hostmp4.com/all-movies or tell me how i do that…
Suspended Ceilings said:
I’d should verify with you here. Which is not one thing I often do! I enjoy studying a submit that will make individuals think. Also, thanks for allowing me to remark!
commercial office cleaning london said:
Excellent read, I just passed this onto a colleague who was doing some research on that. And he just bought me lunch since I found it for him smile Therefore let me rephrase that: Thank you for lunch!
projector lambs said:
It’s actually a nice and helpful piece of information. I am glad that you just shared this helpful information with us. Please stay us informed like this. Thank you for sharing.
Alda Forson said:
Browse all brands of best vacuum cleaner today.