Home › Forums › Add-ons › Flexible Content Field › Flexible Content to Build 404? › Reply To: Flexible Content to Build 404?
Okay I have the 404 page set within settings > reading, and I think I’m like halfway to getting it working on the frontend. I have this code in the 404.php template:
<?php
$post_id = intval(get_option('error_page'));
if (!empty($post_id)) {
$post = get_post($post_id);
setup_postdata($post);
get_template_part('page'); // this is the part where I think I have it wrong?
exit;
}
?>
The normal template that calls all of my flexible content rows is page.php so that’s why I set that in the line for get_template_part. However, it only reads the container div with empty content inside. (This code works on every other page just fine.) I know that just page.php isn’t technically part of a template, so maybe that’s why it doesn’t work? This is the content for that:
<div id="page__content">
<?php
$sectioncount = 0;
while ( have_posts() ) :
the_post();
// are there any rows within within our flexible content?
if( have_rows('page_content', $id )):
$sectioncount;
// loop through all the rows of flexible content
while ( have_rows('page_content', $id )) : the_row();
$sectioncount++;
?>
<?php get_template_part('template-parts/section', 'open'); ?>
<?php get_template_part('partials/page-content/'. get_row_layout()); ?>
<?php get_template_part('template-parts/section', 'close'); ?>
<?php
endwhile; // close the loop of flexible content
endif; // close flexible content conditional
endwhile; // End of the loop.
?>
</div>
See image attached for how it shows up on frontend. I really appreciate your help!
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.