Support

Account

Home Forums Add-ons Flexible Content Field Can I use more than one layout field per page? Reply To: Can I use more than one layout field per page?

  • Hey @acf-support,

    I have narrowed down the issue to be this PHP code which is query the_post(). When this code is in my front-page.php it will display the HTML for my categories, but layout rows after will not output.

    
    switch ( get_row_layout() ) :
    case 'slider':
    echo '<div class="slider">';
    echo 'THE SLIDER';
    echo '</div><!-- @end slider -->';
    break;
    case 'cards':
    echo '<div class="cards">';
    echo 'THE CARDS';
    echo '</div><!-- @end cards -->';
    break;
    case 'custom_html':
    echo '<div class="custom-html">';
    echo 'THE CUSTOM HTML';
    echo '</div><!-- @end custom html -->';
    break;
    case 'dynamic_post':
    
    $section_container = get_sub_field('section_container');
    $section_padding = get_sub_field('section_padding');
    $section_background = get_sub_field('section_background');
    $section_bg_image = get_sub_field('section_bg_image');
    $section_bg_color = get_sub_field('section_bg_color');
    $section_bg_color_stop = get_sub_field('section_bg_color_stop');
    $color_transparency = get_sub_field('color_transparency');
    $gradient_direction = get_sub_field('gradient_direction');
    $section_title = get_sub_field('display_section_title');
    
    $component_type = get_sub_field('content_style');
    $content_type = get_sub_field('content_type');
    $orderby = get_sub_field('order_by');
    $number_of_posts = get_sub_field('number_of_post');
    $categories = get_sub_field('category');
    $name_of_post = get_sub_field('post');
    $name_of_page = get_sub_field('page');
    
    $slider_class = get_sub_field('slider_class');
    
    if ( $content_type === 'category' ) :
    foreach ( $categories as $category ) :
    $cat_slug = $category->slug;
    endforeach;
    
    $args = array(
    'posts_per_page' => (int)$number_of_posts,
    'orderby' => $orderby,
    'category_name' => $cat_slug
    );
    
    $query = new WP_query( $args );
    
    switch ( $component_type ) :
    case 'cards':
    
    if ( $query->have_posts() ) :
    while ( $query->have_posts() ) : $query->the_post();
    											echo '<div class="card--quote">';
    
    												$imgSrc = get_field('image');
    
    												if ( !empty($imgSrc) ) :
    													$imgUrl = $imgSrc['url'];
    													$imgTitle = $imgSrc['title'];
    													$imgAlt = $imgSrc['alt'];
    													$caption = $imgSrc['caption'];
    
    													$imgSize = 'testimonial-thumb';
    													$imgThumb = $imgSrc[ 'sizes' ][ $imgSize ];
    													$imgWidth = $imgSrc['sizes'][ $imgSize . '-width' ];
    													$imgHeight = $imgSrc['sizes'][ $imgSize . '-height' ];
    
    													echo '<div class="card__image">';
    														echo '<img src="' . $imgUrl . '" alt="' . $imgAlt . '" width="' . $imgWidth . '" height="' . $imgHeight . '" />';
    													echo '</div>';
    												endif;
    
    												if ( get_field('quote') ) :
    													echo '<blockquote class="card__quote">';
    														echo '<p>';
    														the_field('quote');
    														echo '<cite>';
    														the_field('cite');
    														echo '</cite>';
    														echo '</p>';
    													echo '</blockquote>';
    												endif;
    
    											echo '</div><!-- @end card quote -->';
    										endwhile;
    endif;
    break;