Is there a way to return different number of posts per row in grid layout based on the post size retrieved from a custom field?
For example:
| Large post |
| Medium post | Medium post |
| Small post | Small post | Small post |
| Medium post | Medium post |
| Large post |
Rows order can be different. I get the post size value from the custom fields. I believe the logics is as follows:
- get the size of a post
- if it fits the row fully, close the row tag, open a new row tag and check the next post
- if the post doesnt fit the entire row, get the next post size and check if it fits
etc.
Any practical ideas?
Thanks a lot.
EDIT: I've already studied a lot of code snippets, which are quite simple. However all of them refer to creating the same number of columns by means of $counter variable and modulus, i.e. dividing the loop into two/three/four column layout. I've never seen a snippet allowing different post sizes in the same grid layout.
Post size is defined in the custom post field. It can be checked by get_post_meta($post_id, '_post_size', true);
An example of the grid with different number of posts per row and different post sizes can be seen at Virgin.