Low Alphabet on Playa fields
Hi there,
I'm trying to alphabetise the results of a Playa field. If this possible?
Here's what I'm trying to do:
Channels
Artists
Art
Books
The artists channel is related to the art and books channels via a playa field, so an artist could have art and books related to them. I need to create a template which lists all artists that have related art and second template that lists artists that have related books. The results need to be listed A-M then N-Z with each letter group wrapped in an unordered list. Example:
- Ableton, Peter
- Anton, Jospeh
- Ashton, Helen
- Batt, Roger
- Beckley, Thomas
- Braithwaite, Sarah
etc.
I can't seem to use my Playa channel field as an alpha_field within Alphabet. Well, I can but it's only brining in the IDs, not names of the artists.
Any ideas? I'm tying myself up in conditionals and embeds trying to get this working but I'm sure there's an elegant way of doing this.
Really hope you can help?
Gary
Replies
Low 20 Jun 2012 10:59
What you can try is use Playa's IDs tags to pass on the relationship's entry_ids to an embed. You can then use the embed variable as input for the entry_ids parameter in the low_alphabet:entries tag.
So, something like
and in the template
The grouping A-M and N-Z isn't possible with Low Alphabet at the moment, but you could use php in your template for that.
Gary Crane 20 Jun 2012 15:02
Thanks Low.
This seems like a good solution. I've been playing around with the {exp:playa:parent_ids} but I seem to be having some problems with the output. It's not rendering the IDs with a | delimiter. I've posted a question on the P&T website. Just waiting for a response. I've tried displaying child and parent IDs but keep getting the same results. For example:
{exp:channel:entries channel="art" disable="categories|member_data|pagination" dynamic="no"}
{exp:playa:child_ids channel="artists"}
{/exp:channel:entries}
139 137 135 133 129 127 125 121 121 13 13 116 114 13 110 108 106 104 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 84 82 80 78 76 74 72 70 68 66 8 8 8 8 8 8 8 8 56 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 27 25 23 19 19 19 13 13 8 8 8 8 8
As a result, I'm struggling to parse any entry ids into an embed.
Any thoughts on this while I'm waiting for P&T?
Gary Crane 20 Jun 2012 15:47
FYI, I'm almost there with the following code, although this is far from an elegant, optimised solution:
{exp:low_alphabet:entries channel="artists" orderby="last_name" alpha_filter="{embed:filter}" disable="categories|member_data|pagination" parse="inward"}
{if count == 1}<ul>{/if}
{if '{exp:playa:total_parents channel="books" status="not Closed"}'}
<li><a href="{url_title_path='books/artist'}"><span class="upper">{last_name}</span>{if first_names}, {first_names}{/if}</a></li>
{/if}
{if count == total_results}</ul>{/if}
{/exp:low_alphabet:entries}
This method ensures that only artists with a book assigned to them are rendered. However it doesn't prevent the
from being added if there aren't any books assigned to artists within the alpha_filter parameter. I have a feeling I may have to dig out my PHP hat.
Low 21 Jun 2012 07:46
Okay, let me know if you run into any other issues.