Return to Snippet

Revision: 66413
at May 1, 2014 17:59 by fedek6


Initial Code
<?php 
				// loop only artists posts
				global $post; // required
				$category_id = ( get_cat_ID( 'Teksty' ) );
				
				$args = array( 
					'category' => $category_id,
					'numberposts'       => -1,
					); 
				$custom_posts = get_posts($args);
				$count = count( $custom_posts );
				
				// only if more posts
				if( $count > 1) {
					// column one
					$col1_count = ceil( $count/2 );
					$col1 = array_slice( $custom_posts, 0, $col1_count );
					// column 2
					$col2_count = ($count - $col1_count);
					$col2 = array_slice( $custom_posts, -$col2_count );					
				}
				else {
					$col1 = &$custom_posts;
					$col2 = array();
				}

				
				// col1
				?>
					<div id="column-1">
					<?php
					foreach($col1 as $post) : setup_postdata($post); ?>
						<?php include (TEMPLATEPATH . '/inc/text-list-item.php'); ?> 
					<?php
					endforeach;
					?>
					</div><!-- #column-1 
					--><div id="column-2">
					<?php
					foreach($col2 as $post) : setup_postdata($post); ?>
						<?php include (TEMPLATEPATH . '/inc/text-list-item.php'); ?> 
					<?php
					endforeach;
					?>
					</div><!-- #column-2 -->

Initial URL


Initial Description
Divide wordpress posts from one category into two columns.

Initial Title
Posts from one category divided into two columns

Initial Tags
wordpress

Initial Language
PHP