Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>from your question, I get the idea that you want to display houses (stored in wordpress post) based on the format of:</p> <pre><code>$data['houses_row'] $data['shown_rows'] </code></pre> <p>The simplest solution is to store what you already have in temporary array first:</p> <pre><code>$temporary_data = array(); while ( have_posts() ) : the_post(); $temporary_data[] = $post;//retrieve current post object endwhile; </code></pre> <p>After you have all post data, begin the second loop to generate it:</p> <pre><code>$current_house_counter = 0; $available_slot = 0; for($shown_row = 0; $shown_row &lt; $data['shown_rows']; $shown_row++) { for($house_row = 0; $house_row &lt; $data['houses_row']; $house_row++) { if( isset($temporary_data[$current_house_counter]) ) { echo "show house: #". ($current_house_counter + 1) ." "; } else { $available_slot++; echo "available slot #" . $available_slot . " "; } $current_house_counter++; } echo "&lt;hr /&gt;"; } </code></pre> <p>Because I don't have a wordpress installation at the moment, I'll give you this code snippet to test it out:</p> <pre><code>$temporary_data[] = "data #1"; $temporary_data[] = "data #2"; $temporary_data[] = "data #3"; $temporary_data[] = "data #4"; $temporary_data[] = "data #5"; $data['houses_row'] = 3; $data['shown_rows'] = 3; $current_house_counter = 0; $available_slot = 0; for($shown_row = 0; $shown_row &lt; $data['shown_rows']; $shown_row++) { for($house_row = 0; $house_row &lt; $data['houses_row']; $house_row++) { if( isset($temporary_data[$current_house_counter]) ) { echo "show house: #". ($current_house_counter + 1) ." "; } else { $available_slot++; echo "available slot #" . $available_slot . " "; } $current_house_counter++; } echo "&lt;hr /&gt;"; } </code></pre> <p>The code above has the following result:</p> <pre><code>show house: #1 show house: #2 show house: #3 &lt;hr /&gt; show house: #4 show house: #5 available slot #1 &lt;hr /&gt; available slot #2 available slot #3 available slot #4 &lt;hr /&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload