Skip to content

Instantly share code, notes, and snippets.

@gregoirenoyelle
Last active February 20, 2017 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregoirenoyelle/8c35f82d33ae7c724372 to your computer and use it in GitHub Desktop.
Save gregoirenoyelle/8c35f82d33ae7c724372 to your computer and use it in GitHub Desktop.
ACF PRO Repeater et Flexible
<?php
// Template Name: Page avec Flexible
add_action( 'genesis_entry_content', 'gn_flexible_content', 50);
function gn_flexible_content() {
// Contrôle si le flexible a des champs
if( have_rows('flexible_content_field_name') ):
// boucle sur les champs du flexible
while ( have_rows('flexible_content_field_name') ) : the_row();
if( get_row_layout() == 'paragraph' ):
the_sub_field('text');
elseif( get_row_layout() == 'download' ):
$file = get_sub_field('file');
endif;
endwhile;
else :
// pas de champs flexible
echo "pas de champ Flexible dans le coin !";
endif;
} // function gn_flexible_content()
genesis();
<?php
// Template Name: Page avec Repeater
add_action( 'genesis_entry_content', 'gn_repeater_content', 50);
function gn_repeater_content() {
// Contrôle si le repeater a des champs
if( have_rows('repeater_field_name') ):
// boucle sur les champs du repeater
while ( have_rows('repeater_field_name') ) : the_row();
// affichage des sous-champs
the_sub_field('sub_field_name');
endwhile;
else :
// pas de champs Repeater
echo "pas de champ Repeater dans le coin !";
endif;
} // function gn_repeater_content()
genesis();
<?php
/**
* Template Name: Page avec Flexible
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Contrôle si le flexible a des champs
if( have_rows('flexible_content_field_name') ):
// boucle sur les champs du flexible
while ( have_rows('flexible_content_field_name') ) : the_row();
if( get_row_layout() == 'paragraph' ):
the_sub_field('text');
elseif( get_row_layout() == 'download' ):
$file = get_sub_field('file');
endif;
endwhile;
else :
// pas de champs flexible
echo "pas de champ Flexible dans le coin !";
endif;
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
<?php
/**
* Template Name: Page avec Repeater
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Contrôle si le repeater a des champs
if( have_rows('repeater_field_name') ):
// boucle sur les champs du repeater
while ( have_rows('repeater_field_name') ) : the_row();
// affichage des sous-champs
the_sub_field('sub_field_name');
endwhile;
else :
// pas de champs Repeater
echo "pas de champ Repeater dans le coin !";
endif;
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment