I just knocked up a quick extension to make it easier to create A to Z indexes of entries.
It creates a new column in exp_weblog_titles and adds the first character of the entry’s title.
You get a new parameter “title_alpha” to add to your exp:weblog:entries tag. Example:
{exp:weblog:entries weblog="showcase|blog|features" title_alpha="{segment_3}" dynamic="off"}
or
{exp:weblog:entries weblog="showcase|blog|features" title_alpha="a|b|c" dynamic="off"}
You can see it in action here. Just change the third segment to a letter to filter. There’s no support for foreign characters.
I’ve tested it on a couple of sites without problems but don’t try it on anything critical until I’ve gained some feedback.
Any suggestions for improvement?
You’re just too quick for us Lisa 😉
BTW, the only reason I say don’t try it on critical stuff now is that when the extension is enabled it runs through all your entries and adds the first character to the title_alpha column. I could probably improve the performance of this query as I’m not sure how it’ll handle sites with 1000s of existing entries.
I would probably prefix the new column name. It’s not likely that we will add a column with that name, but by prefixing it with some something short and unique, you can be more assured that you are protected against potential collision, not only with first party changes, but with other third party add-ons a user might be using. And yes, one query per entry, all at once, is probably not the best implementation. As a matter of fact, I believe that you could do this with a single query, using MySQL’s built in string functions.
Hm.. come to think of it, I probably wouldn’t create another column unless its really neccessary for performance. I’ll have to extend Derek’s line of though here, it’s potentially hasardous to alter the core tables, compared to adding a cpu-cycle and a half to each query.
SELECT entry_id FROM exp_weblog_titles WHERE LEFT(LOWER(title), 1) = 'a';
What are your thoughts on this?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.