6. have_rows() et the_row() | Field Forge - Champs personnalisés, conçus pour la vitesse
Télécharger Se connecter

6. have_rows() et the_row()

Utilisé avec les champs Répéteur, Groupe et Contenu Flexible pour itérer à travers des données structurées.

have_rows( $selector, $post_id ) / the_row()

Paramètres :
ParamètreTypePar défautDescription
$selectorstringNom du champ répétiteur, groupe ou contenu flexible
$post_idint\string\falsefalseID de publication, 'options', ou false pour la publication actuelle
Renvoie : booltrue si des lignes existent et qu’il y a plus de lignes à itérer.
php
// Basic repeater loop
if ( have_rows( 'team_members' ) ) :
    while ( have_rows( 'team_members' ) ) : the_row();
        $name  = get_sub_field( 'name' );
        $photo = get_sub_field( 'photo' );
        echo '<div class="team-member">';
        echo '<h3>' . esc_html( $name ) . '</h3>';
        if ( $photo ) {
            echo '<img src="' . esc_url( $photo ) . '" alt="">';
        }
        echo '</div>';
    endwhile;
endif;

// Repeater from a specific post
if ( have_rows( 'pricing_tiers', 99 ) ) :
    while ( have_rows( 'pricing_tiers', 99 ) ) : the_row();
        echo '<div class="tier">';
        echo '<h3>' . esc_html( get_sub_field( 'plan_name' ) ) . '</h3>';
        echo '<p class="price">$' . esc_html( get_sub_field( 'price' ) ) . '/mo</p>';
        echo '</div>';
    endwhile;
endif;

// Repeater from options page
if ( have_rows( 'announcement_bar', 'options' ) ) :
    while ( have_rows( 'announcement_bar', 'options' ) ) : the_row();
        echo '<div class="announcement">' . esc_html( get_sub_field( 'message' ) ) . '</div>';
    endwhile;
endif;

Assistant IA Forge En ligne

Bonjour ! Je suis l'assistant IA Field Forge. Posez-moi n'importe quelle question sur le plugin — configuration, fonctionnalités, dépannage ou développement.

À l'instant
Propulsé par Forge IA · Parcourir la documentation