Home Forums Add-ons Flexible Content Field Flexible Content Row in Footer?


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):?>
    			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>
    							$form_id= $form->ID;
    							echo do_shortcode( '[contact-form-7 id="'.$form_id.'" ]' ); ?>
    				<?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.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.