Reputation: 13
I have looked at other examples and attempted to get this to work but the modifications to the code return only errors. Basically, I have a list of categories that are pulled from my database and displayed on 2 columns. I would like to have the categories listed alphabetically with the first half of the list in column 1 and the second half in column 2. I assume simply listing them alphabetically will automatically display them in the categories as I want. Thanks for any help. The code I have is:
<ul class="links">
<?php if($this->is_loged) { ?>
<li><a href="./"><strong><?php echo $this->translate('Pinners you follow');?></strong></a></li>
<?php } ?>
<?php if($this->categories) { ?>
<li>
<a class="arrow" href="<?php echo $this->all_url;?>"><?php echo $this->translate('Everything');?><?php if($this->category_active) { ?>: <?php echo $this->category_active;?><?php } ?></a>
<div class="dropdown columns-2">
<?php $total = count($this->categories); ?>
<?php for($r=$i=0; $i<2; $i++) { ?>
<ul>
<?php for($j=0; $j<ceil( $total/2 ); $j++, $r++) { ?>
<?php if(isset($this->categories[$r])) { ?>
<?php
$class = $this->categories[$r]['active'] ? 'active' : '';
if($r==0 || ceil( $total/2 ) == $r) { $class .= ' first'; }
if($r==($total-1) || (ceil( $total/2 )-1) == $r) { $class .= ' last'; }
$class = trim($class);
?>
<li<?php if($class) {?> class="<?php echo $class;?>"<?php } ?>><a href="<?php echo $this->categories[$r]['href'];?>"><?php echo $this->categories[$r]['title'];?></a></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
<div class="clear"></div>
</div>
</li>
<?php } ?></ul>
Upvotes: 1
Views: 586
Reputation: 4560
You can do this with MySQL sort_by name ASC
, in PHP you can do this whith:
sort($this->categories, SORT_STRING)
or sort($this->categories)
;ksort($this->categories)
sort with keys;Upvotes: 1