Creating a new container for post once post limit is reached

Sorry if the title is a bit vague but what i’m trying to achieve is that once a certain a amount of post has been reached a new container will be created to fill it with post.

Please see this screenshot for reference

If you look at it closely their is a white border surrounding the container

This is the code i have done at the moment. The result i’m trying to achieve is the screenshot above

		<section class="grid_12 aftersix_dresses_container">
		     <?php query_posts('posts_per_page=-1&cat=11'); if(have_posts()) : while(have_posts()) :the_post(); ?>
		
		     <?php
             $url = MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-image');
		     ?>
		
		    <div class="aftersix_thumbnails">
			  <?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); echo '<img src="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '">';  } ?>
			
			  	<div class="hover_dress">
					<a class="fancybox" href="<?php echo $url; ?>"><span><?php the_title(); ?></span></a>
			    </div>
	
			</div>
		
		    <?php endwhile; endif; wp_reset_query();?>
		</section>

Ok I think what you want is that say if each row can accommodate 3 posts then after 3 posts a new row is created with another 3 posts.

This is easy. What you need to do is run the loop with a counter so if say you need 3 posts per row, then when the counter reaches 3 close the first container and start another container and reset the counter.

For example begin counter == 0 then just before loop ends counter++. finally check if counter 3 then close the container and begin a new container. The white border would be via a single css code.

Basically i just need to utilize “if, else” and also create a variable for the counter.

Yes you can do that using any logic. So if you are using if / else logic then you need to run the loop until loop is at 3 and then begin the new row container and close the existing row container.

Alright thanks for the info. I think the need to put two if else statement. 1.) The first if else is too display a new container. 2) To count the number of post. Correct me if i’m wrong. I’m still a bit new to PHP

Well I think one if statement would do so the logic would be if counter equals 3 then enter the loop > close the old container > open a new container and then reset the counter to 0.

I seem to having trouble trying to code it and getting php errors

Basically i created a variable $post = query_posts(‘posts_per_page=-1&cat=11’); then before “section tag” i created an if else statement but the result displayed was a PHP error :frowning:

		<section class="grid_12 aftersix_dresses_container">
		     <?php query_posts('posts_per_page=-1&cat=11'); if(have_posts()) : while(have_posts()) :the_post(); ?>
		  
		     <?php 
             $url = MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-image');
		     ?>
		  
		    <div class="aftersix_thumbnails">
			  <?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); echo '<img src="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '">';  } ?>
			  
			  	<div class="hover_dress">
					<a class="fancybox" href="<?php echo $url; ?>"><span><?php the_title(); ?></span></a>
			    </div>
	
			</div>
		  
		    <?php endwhile; endif; wp_reset_query();?>
		</section>

I managed to get the results that i wanted but only different and a bit wrong. Basically i had to call the specific category like “Row One” or “Row Two” and query the post. It’s a bit of a hassle since i need to create a category. I’m still having trouble trying to fix the code above

Hi, I think here is what you need to do : there are 2 things you need to remember 1 is the outer container and the second is the inner container. The outer container is the white border and then for each image its the inner container. So you will open and close each inner container after each loop while the outer container will need to be closed after 3 loops (as you want 3 in each row). Thats the logic and you can definitely create a code based on that.

The problem is the code in order to make that logic work. Still getting a lot of PHP errors and this is the only alternative i can think of at the moment.