I have a list of cities and states that populates from a channel. My code looks like this:
<ul class="dropdown-menu">
{exp:channel:entries channel="areas" dynamic="no" orderby="area_state|title" sort="asc|asc"}
{area_state}
<li><a href="http://{path=area/{url_title}}">{title}</a></li>
{/exp:channel:entries}
</ul>I am able to sort the list and display as folows:
I need to display it like:
I have been able to display like:
Just not like I need. Could anyone help me with the proper way to write this List? Thanks in advance, this has been bugging me.
I don’t think you will be able to achieve that with just standard EE template code. You will probably have to use some PHP in the template. Try this (PHP parsed on output):
<?php $areas = array(); ?>
{exp:channel:entries channel="areas" dynamic="no" orderby="area_state|title" sort="asc|asc"}
<?php $areas['{area_state}'][] = '<a href="http://{path=area/{url_title}}">{title}</a>'; ?>
{/exp:channel:entries}
<ul class="dropdown-menu">
<?php foreach($areas as $state => $state_areas): ?>
<?php echo $state; ?>
<?php foreach($state_areas as $area): ?>
<li><?php echo $area; ?></li>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.