Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP While control structure in Wordpress
    primarykey
    data
    text
    <p>I've been struggling with the PHP While control structure in Wordpress. I definitely know this is possible, just don't know exactly how to do it. </p> <p>I'm using the Wordpress database to store my widget controls form fields data, and I want to loop through the data with this code.</p> <pre><code>need to control structure by the 2 numbers defined in my widget control. $data['houses_row'] $data['shown_rows'] </code></pre> <p>Here's what I'm trying to do:</p> <p>I'm thinking of Houses and each one is on a plot of land as an analogy. Sort of.</p> <p>How many houses to show per row? and How many rows to show?</p> <p>If the row has more houses than the row can handle then those houses need to be hidden, which this can do naturally. I am thinking many houses to many rows.</p> <p>I hope somebody can help me with my loop.</p> <pre><code> static $number_posts_shown = 1; static $per_row_count = 0; while ( have_posts() ) : the_post(); if ( $per_row_count &lt;= $data['houses_row'] ): echo "show house: #". $per_row_count ." "; endif; $per_row_count++; // show rows if ( $number_posts_shown &lt;= $data['shown_rows'] ): echo "&lt;hr /&gt;"; endif; $number_posts_shown++; endwhile; </code></pre> <p>when shown_rows is 4 and houses_row(houses per row) is 4 I wanted the output to be this.</p> <pre><code>show house: #0 show house: #1 show house: #2 show house: #3 -------------------------------------------------------------------------------- blank -------------------------------------------------------------------------------- blank -------------------------------------------------------------------------------- blank </code></pre> <p>when shown_rows is 4 and houses_row(houses per row) is 2 the output is this.</p> <pre><code>show house: #0 show house: #1 -------------------------------------------------------------------------------- show house: #2 show house: #3 -------------------------------------------------------------------------------- blank row -------------------------------------------------------------------------------- blank row </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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