• Resolved kikimarie123

    (@kikimarie123)


    I have an unordered list (of team members) that I want to automatically separate into two columns – even when new team members are added. Is there a way to do this? Here is my code:

    <div class="team-list">
    <?php $args = array(
    	'posts_per_page'  => -1,
    	'post_type' => 'team-members',
    	'meta_query' => array(
    		array(
    			'key' => 'team_member_category',
    			'value' => '"Alphabetical Listing"',
    			'compare' => 'LIKE'
    		)
    	)
    );
    $the_query = new WP_Query( $args ); ?>
    <?php if( $the_query->have_posts() ): ?>
    	<ul>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                    <li>
    		<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" ><?php the_title(); ?></a>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    <?php endif; ?>
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>
    
    </div><!--end .team-list -->

    Help please!! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • one possibility:

    <?php if( $the_query->have_posts() ): ?>
    	<ul <?php if( $the_query->post_count > 1 ) echo 'class="first-half"'; ?>>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    	<?php if( $the_query->current_post == ceil($the_query->post_count/2) ) echo '</ul><ul class="second-half">'; ?>
                    <li>
    		<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" ><?php the_title(); ?></a>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    <?php endif; ?>
    <?php wp_reset_postdata();  // Restore global post data stomped by the_post(). ?>

    CSS example:

    .first-half, .second-half { width: 50%; float: left; display: inline; }
    .second-half:after { content: '.'; float: left; width: 100%; clear: both; display: block; height: 1.5em; visibility: hidden; }

    Thread Starter kikimarie123

    (@kikimarie123)

    Thank you so much!! Worked like a charm!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Separate list into two even columns’ is closed to new replies.