Two column layout with alphabetical ordering
I am trying to output a list of stockists in two columns from left to
right, sorted alphabetically:
A | B
C | D
E | F
G | H
Currently, the code below is sorting half the posts alphabeticly and then
starting half way through with the rest alphabeticly:
A | C
E | G
B | D
F | H
Any idea on where I am going wrong?
<?php
query_posts( array( 'order' => 'ASC' , 'orderby' => 'title' ,
'posts_per_page' => -1 , 'post_type' => 'stockist_directory', 'regions' =>
'metropolitan' ) );
if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) :
$wp_query->next_post(); else : the_post(); ?>
<div id="left-column">
<h1><?php the_title(); ?></h1>
<?php the_field('shop_address'); ?><br/>
<?php the_field('suburb'); ?>, <?php the_field('postcode'); ?><br/>
Phone: <?php the_field('phone_number'); ?><br/>
<a href="<?php the_field('website_address'); ?>">Website</a>
</div>
<?php endif; endwhile; else: ?>
<?php endif; ?>
<?php $i = 0; rewind_posts(); ?>
<?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) :
$wp_query->next_post(); else : the_post(); ?>
<div id="right-column">
<h1><?php the_title(); ?></h1>
<?php the_field('shop_address'); ?><br/>
<?php the_field('suburb'); ?>, <?php the_field('postcode'); ?><br/>
Phone: <?php the_field('phone_number'); ?><br/>
<a href="<?php the_field('website_address'); ?>">Website</a>
</div>
<?php endif; endwhile; else: ?>
<?php endif; ?>
No comments:
Post a Comment