Home › Forums › Add-ons › Flexible Content Field › Flexible Content Row in Footer?
I have a flexible content row for a newsletter form, and it works perfectly within any page content. However, I also want to include this row in the footer if the option is checked on the options page. It works how it’s supposed to, BUT the issue seems to be that it only appears in the footer IF this content row also appears in the current page. For example, the form is a flexible content row on the homepage, so the newsletter also appears in the footer, but the form isn’t a flexible content row on any other page, so the newsletter doesn’t show.
Here is the code I have for the footer:
<?php $newsletter = get_field('footer_newsletter','option'); ?> <?php if($newsletter):?> <?php if( have_rows('page_content') ): while ( have_rows('page_content') ) : the_row(); if( get_row_layout() == 'form' ): $form = get_sub_field('choose_form'); $style = get_sub_field('form_style'); $title = get_sub_field('form_title'); $subtitle = get_sub_field('form_subtitle');?> <?php if($style == "newsletter") :?> <section class="footer__form <?php echo get_row_layout(); ?> style-<?php echo $style;?>"> <div class="container width-wide"> <small class="newsletter__subtitle"><?php echo $subtitle;?></small> <h4><?php echo $title; ?></h4> <?php $form_id= $form->ID; echo do_shortcode( '[contact-form-7 id="'.$form_id.'" ]' ); ?> </div> </section> <?php endif; ?> <?php endif; endwhile; endif;?> <?php endif; ?>
I feel like my issue might lie somewhere in my if statement for have_rows.
You need to supply the post ID for the home page, or whatever page holds the flex field content.
if( have_rows('page_content', get_option('page_on_front')) ): while ( have_rows('page_content', get_option('page_on_front')) ): ....
So this is only possible if the flexible content is somewhere as a row on a page of the website, correct?
Or a row on an options page. Then you would use ‘options’ as the ID the same way you used it in your get_field() call.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.