Home » Topics » General Support » Widget with Flexible Content

Widget with Flexible Content

ACF Widgets Support General Support Widget with Flexible Content

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #94881
    Greg Miller
    Participant

    Hello,

    I’m a new customer and have been working with ACF Pro for a few months. I have a flexible content field which works in the widget. I have been unable to get demo content to appear on the page and I am wondering if you could help me. I’m building a version of a ‘hello bar’ which I’m calling ‘promo bar’. This bar is to have text, image icon, and a button. I’m just trying to get text to show up. I’ve added a little text to my widget but it is not resolving to the page. The rendered html returns the layout (below) sans text.

    The template file was saved to the root of the theme with the name given in the widget debug screen. Have I screwed something up in the template? What else could I check? I’ve been reading the doc on ACF.

    Thanks in advance,
    Greg

    Template Code
    `<div id=”promobar”>
    <p class=’promotext’>
    <?php if ( have_rows( ‘tt_bar’ ) ): ?>
    <?php while ( have_rows( ‘tt_bar’ ) ) : the_row(); ?>

    <?php if ( get_row_layout() == ‘promotion_image’ ) :

    <!– Add pic –>
    // vars
    $pic = wp_get_attachment_image(get_sub_field(‘new_image’, $acfw ),’full’,
    false, $attr=array(‘class’ => ‘img-responsive size-icon’));
    ?>

    <?php echo $pic; ?>

    <!– Add text –>
    <?php elseif ( get_row_layout() == ‘tt_bar_text’ ) : ?>
    <?php the_sub_field( ‘promo_text’, $acfw ); ?>

    <!– Add button –>
    <?php elseif ( get_row_layout() == ‘tt_bar_button’ ) : ?>
    <?php if ( have_rows( ‘add_button’ ) ) : ?>

    <?php while ( have_rows( ‘add_button’, $acfw ) ) : the_row(); ?>

    ” class=’promo-button’ target=”<?php
    the_sub_field( ‘hb_button_tab’, $acfw ); ?>” ><?php the_sub_field( ‘hb_button’, $acfw ); ?>

    <?php endwhile; ?>
    <?php else : ?>
    <?php // no rows found ?>
    <?php endif; ?>
    <?php endif; ?>
    <?php endwhile; ?>
    <?php else: ?>
    <?php // no layouts found ?>
    <?php endif; ?>
    </p>
    </div>

    #94883
    Greg Miller
    Participant

    I simplified and reworked my code. Currently all text items display but image items are not. I’d like help setting image_id. Here’s my code.

    Template Code:

    <div id="promobar">
     <p class='promotext'>
       
       <?php if ( have_rows( 'flex', $acfw ) ): ?>
         <?php while ( have_rows( 'flex', $acfw ) ) : the_row(); ?>
    
           <?php if ( get_row_layout() == 'text_box' ) : ?>
             <?php the_sub_field( 'promo_text', $acfw ); ?>
    
             <?php if ( $image ) { ?>
               <?php echo wp_get_attachment_image( $image, 'full', $acfw ); ?>
             <?php } ?>
    
           <?php elseif ( get_row_layout() == 'button' ) : ?>
             <?php the_sub_field( 'button', $acfw ); ?>
    
           <?php endif; ?>
         <?php endwhile; ?>
       <?php else: ?>
         <?php // no layouts found ?>
       <?php endif; ?>
    
        </p>
    </div>
    #94884
    Greg Miller
    Participant

    OK, my problem is all sorted now.

    Lessons learned for a first timer is to simplify everything down to the simplest forms. The $acfw parameter should be applied to all flexible content loops. Like:

    <?php if ( have_rows( 'flex', $acfw ) ): ?>

    But not to layout structures:
    <?php elseif ( get_row_layout() == 'image_box' ) : ?>

    I recommend people try ACF add-on, Theme Code Pro which aided me in writing the conditional structures. Like this plugin, it’s totally worth it for the time it saves you.

    Cheers,
    Greg

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Widget with Flexible Content’ is closed to new replies.