0

I'm making a people directory index and would like A-Z links, where clicking on a letter produces all people whose last names begins in that letter.

I'm pulling from a People channel, which has a Last Name field, but it doesn't look like the exp:channel:entries search parameter can search on just the first character of a field?

Is there an easy way to do this? My next idea is running SQL WHERE last_name LIKE 'x%', but I'd prefer a more elegant solution if one exists.

2

You could try http://gotolow.com/addons/low-alphabet as that allows you to group entries by letters (and numbers if you need).

1

(Is this the same question Making a directory's A - B - C - D etc. links ?)

I had the same issue, and made a solution that might / might not suit your setup, and post it here. I use Profile:edit to connect Memberfields with a 'peoples channel' and dynamic parameters for searching.

1) New members get accepted by an admin who also fills in a Channel form for member_profiles (= 'the peoples channel'). This form does a few things, but this part extracts the first letter from their last name.

<input type="hidden" name="member_letter" value="{exp:trunchtml chars="1"}{member_last_name}{/exp:trunchtml}">

2) This field 'member_letter' is searchable.

3) On my search page I have this:

<form id="artists_lettersEmpty" class="float-right" method="post" action="{path='{segment_1}/{segment_2}/'}">
    <input id="symbol" class="button tiny callout LastButton" name="search:member_letter" type="submit" value="&#x21ba;">
</form>
<form id="artists_letters" class="float-right" method="post" action="{path='{segment_1}/{segment_2}/medlem'}">
    <input id="a" class="button tiny letter" name="search:member_letter" type="submit" value="A"> <input id="b" class="button tiny letter" name="search:member_letter" type="submit" value="B"> <input id="c" class="button tiny letter" name="search:member_letter" type="submit" value="C"> <input id="d" class="button tiny letter" name="search:member_letter" type="submit" value="D"> <input id="e" class="button tiny letter" name="search:member_letter" type="submit" value="E"> <input id="f" class="button tiny letter" name="search:member_letter" type="submit" value="F"> <input id="g" class="button tiny letter" name="search:member_letter" type="submit" value="G"> <input id="h" class="button tiny letter" name="search:member_letter" type="submit" value="H"> <input id="i" class="button tiny letter" name="search:member_letter" type="submit" value="I"> <input id="j" class="button tiny letter" name="search:member_letter" type="submit" value="J"> <input id="k" class="button tiny letter" name="search:member_letter" type="submit" value="K"> <input id="l" class="button tiny letter" name="search:member_letter" type="submit" value="L"> <input id="m" class="button tiny letter" name="search:member_letter" type="submit" value="M"> <input id="n" class="button tiny letter" name="search:member_letter" type="submit" value="N"> <input id="o" class="button tiny letter" name="search:member_letter" type="submit" value="O"> <input id="p" class="button tiny letter" name="search:member_letter" type="submit" value="P"> <input id="q" class="button tiny letter" name="search:member_letter" type="submit" value="Q"> <input id="r" class="button tiny letter" name="search:member_letter" type="submit" value="R"> <input id="s" class="button tiny letter" name="search:member_letter" type="submit" value="S"> <input id="t" class="button tiny letter" name="search:member_letter" type="submit" value="T"> <input id="u" class="button tiny letter" name="search:member_letter" type="submit" value="U"> <input id="v" class="button tiny letter" name="search:member_letter" type="submit" value="V"> <input id="w" class="button tiny letter" name="search:member_letter" type="submit" value="W"> <input id="x" class="button tiny letter" name="search:member_letter" type="submit" value="X"> <input id="y" class="button tiny letter" name="search:member_letter" type="submit" value="Y"> <input id="z" class="button tiny letter" name="search:member_letter" type="submit" value="Z"> <input id="å" class="button tiny letter" name="search:member_letter" type="submit" value="Å"> <input id="ä" class="button tiny letter" name="search:member_letter" type="submit" value="Ä"> <input id="ö" class="button tiny letter" name="search:member_letter" type="submit" value="Ö">
</form>

3) form id="artists_lettersEmpty" resets the form (by searching without letter)

4) form id="artists_letters" searches after the visitor clicks the button with that letter. As you see, we ae on a Swedish site.

5) Result shows up here:

    <h4>Resultat:</h4>
{exp:channel:entries
channel="member_profiles"
disable="pagination|category-fields|member-data|relations"
dynamic_parameters="search:member_letter"
orderby="member_last_name"
sort="asc"
dynamic="off"}
{member_first_name} {member_last_name}
{/exp:channel:entries}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.