Add opening and closing tags for categories list from a to z

Hello,

I want to know if it is possible to add opening tag
<ul><li> and closing tag </li></ul>
after character change for example:

(‘a’,‘z’)

if character starts with new letter add opening and closing tag

    <li>Animation</li>
    <li>Arts &Design</li>
    <li>Cameras</li>
    <li>Comedy</li>
    <li>Documentary</li>
    <li>Designers</li>
    <li>Experimental</li>

to

<ul>

<li>Animation</li>
<li>Arts &Design</li>

</ul>
<ul>

<li>Cameras</li>
<li>Comedy</li>
</ul>
<ul>
<li>Documentary</li>
<li>Designers</li>
</ul>
<ul>
<li>Experimental</li>
</ul>

Thanks in advance.

Yes, it is possible.

In your loop to display the list items, keep a track of the starting letter of the previous entry. If it’s different from the one you are about to display, close the previous ul tag (if there was one open), and open a new one. Pseudo-code:

previous-start-letter = "";
opentag = false;
while (get-next-record) {
  if (new-record-start-letter <> previous-start-letter) { 
    if (opentag) output closing ul tag
    output opening ul tag
    set opentag to true
    }
  display list item
  set previous-start-letter to new-record-start letter
  }
if (opentag) output closing ul tag
1 Like

Thank you very much.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.