Get row index (ACF): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
(Nieuwe pagina aangemaakt met '<code>get_row_index()</code> returns the current row index within a <code>have_rows()</code> loop. Whilst stepping though the rows of a Repeater or Flexible Conten...')
 
 
(Een tussenliggende versie door dezelfde gebruiker niet weergegeven)
Regel 2: Regel 2:
  
 
Whilst stepping though the rows of a Repeater or Flexible Content field, you may find it necessary to determine the row number (index). This function does exactly that, avoiding the need of a custom $i++ counter.
 
Whilst stepping though the rows of a Repeater or Flexible Content field, you may find it necessary to determine the row number (index). This function does exactly that, avoiding the need of a custom $i++ counter.
 +
 +
Rows start at 1 (not 0) [https://www.advancedcustomfields.com/resources/update_sub_row/]
 +
 +
== Voorbeeld ==
 +
 +
<pre>
 +
while (have_rows('add_code_to_head', 'option')):
 +
  echo(get_row_index());
 +
  print_r(the_row(true));
 +
  echo(get_row_index());
 +
endwhile;
 +
</pre>
  
 
== Bronnen ==
 
== Bronnen ==
  
 
* https://www.advancedcustomfields.com/resources/get_row_index/
 
* https://www.advancedcustomfields.com/resources/get_row_index/

Huidige versie van 29 jul 2022 om 16:02

get_row_index() returns the current row index within a have_rows() loop.

Whilst stepping though the rows of a Repeater or Flexible Content field, you may find it necessary to determine the row number (index). This function does exactly that, avoiding the need of a custom $i++ counter.

Rows start at 1 (not 0) [1]

Voorbeeld

while (have_rows('add_code_to_head', 'option')):
   echo(get_row_index());
   print_r(the_row(true));
   echo(get_row_index());
endwhile;

Bronnen