0

I'd like to use something similar to a switch or plugin like Grouper with category_archive, to wrap a <ul> around every 6 <li>, but I don't see anything that works. Is jQuery the best way to go or is the another solution I can use that doesn't need js/jQuery?

<ul class="list-unstyled">
    {exp:channel:category_archive channel="speakers" style="linear" backspace="7"}
        <li>
            {categories}
                <a href="#">{category_name}</a>
            {/categories} 
            {entry_titles}  
            <ul class="list-unstyled"> 
                <li><a href="{url_title_path='site/speaker'}">{title}</a></li>
            </ul>  
            {/entry_titles}     
        </li>   
    {/exp:channel:category_archive}     
</ul>
1
  • I don't think this can be done, because exp:channel:category_archive doesn't use the Template Parser, so there aren't count or total_results variables.
    – Sobral
    Jun 12 '15 at 18:05
0

Take a look at the conditionals available. https://ellislab.com/expressionengine/user-guide/templates/conditionals.html#mathematic-operators Particularly the modulus operator.

2
  • Can't seem to get global variables like {count} to work in category_archive entry so not sure I can accomplish this way...unless I'm missing something. Thoughts?
    – frshjb373
    Jun 12 '15 at 17:25
  • A few lines or so of PHP should work. You'll set a counter just before the loop, then increment this counter for every lap of the loop, divide by six and check the remainder.
    – Ingmar
    Dec 11 '15 at 15:52
0

i've done something similar to this before, though a bit different, test something like this using the Switchee plugin.

{exp:channel:category_archive channel="speakers" style="linear" backspace="7"}
{switch="<ul class='list-unstyled'>|||||"}{!-- open a new <ul> at intervals of 6 entries --}
<li>
{categories}<a href="#">{category_name}</a>{/categories} 
{entry_titles}  
<ul class="list-unstyled"> 
<li><a href="{url_title_path='site/speaker'}">{title}</a></li>
</ul>  
{/entry_titles}     
</li>  
{if count != total_results}{switch="|||||</ul>"}{/if} {!-- close the </ul> at intervals of 6 as long as the current entry is not the last in the loop --}
{if count == total_results}</ul>{/if} {!-- always close the open </ul> after the last entry --}
{/exp:channel:category_archive} 

Hope that helps?

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.