Archived topic
Advanced Custom Fields and Sections
6 replies · Started by Beau on July 19, 2017
I have a food menu I built using ACF Pro and it works great when the menu page that is using the template doesn't have Sections turned on for the remaining content. When it does, all of the data in the ACF disappears. How can I dig that content out from the Sections and add it to the template?
https://www.perkinscovetrap.com/menu-2/
password: yo
Thanks,
Beau
Hi there,
How are the fields from ACF being output on the page where it's working? Using a custom page template?
Yes exactly - pretty bare bones template. Is there other code that brings in the content from the sections that I'm missing?
Sections itself using a custom page template, so I don't think you'll be able to use the two together.
However, you should be able to build your own sections inside your page template without using the Sections add-on.
Ya I was actually trying to do that last night, but I can't seem to get my images to stretch full width (like what the sections do) - the sides of the images keep hitting the margins.
Here's what I have for the template:
<?php
/*
Template Name: Menu
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
</header><!-- .entry-header -->
<div class="entry-content" style="padding:0;">
<?php the_content(); ?>
<h1>Our Menu</h1>
<?php if ( have_rows('menu_sections') ):
while ( have_rows('menu_sections') ): the_row(); ?>
<h2 class="section-title"><?php the_sub_field('section_title'); ?></h2>
<span class="section-description"><?php the_sub_field('section_description'); ?></span><hr>
<?php if ( have_rows('section_items') ): ?>
<table class="menu">
<?php while ( have_rows('section_items') ): the_row(); ?>
<tr>
<td width="60%" valign="top"><span class="dish-title"><?php the_sub_field('dish_name'); ?></span><br>
<span class="dish-description"><?php the_sub_field('dish_description'); ?></span></td>
<td width="40%" valign="top"><div class="dish-price"><?php the_sub_field('dish_price'); ?></div></td>
</tr>
<tr>
<td colspan="2" valign="top"><br><br></td>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>
<?php endwhile;
endif; ?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
<?php endwhile; // End the loop. ?>
* Consuming raw or undercooked foods may increase your risk of food-borne illness
</main><!-- .site-main -->
</div><!-- .content-area -->
</div>
<?php get_footer(); ?>
Never mind I got it! I added a simple if/then check in header.php to see if it was the Menu page and if it was, added in the full width image.
https://www.perkinscovetrap.com/menu/
password: yo
Thanks again for everything! F'ing love working w/ GP.
Awesome, look great! :)