Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKristian Woods
23,414 PointsWordpress and Advanced Custom Fields Issue
I have wordpress set up with afc and I've created two repeater fields, which I've included on the page. In my header, I have a repeater field to display a carousel slider. Then below the header, I include my page content in a basic div. I've added the masthead.php into the front-page.php just below the get_header().
For some reason, I'm only getting the header when I load the page. Everything below the header tag disappears. However, when I comment out the include function to pull in the masthead.php, my main content displays, but without the header, of course. There seems to be some sort of conflict.
I checked my php_error.log, and it gave me this:
PHP Parse error: syntax error, unexpected '<' in [folder_structure]/masthead.php on line 64
I have checked and double checked my afc fields to ensure its not a typo or I'm not looping through the right thing. But it looks good to me...
<header>
<?php
$defaults = array (
'theme_location' => 'main-navigation',
'menu_class' => 'no-bullet',
'container' => false
); ?>
<nav class="main-header-nav">
<img src="<?php echo get_template_directory_uri();?>/icons/Hilton-logo.svg" alt="Hilton Logo" class="header-logo">
<?php wp_nav_menu($defaults); ?>
</nav>
<?php if( have_rows('header_carousel') ): ?>
<?php while( have_rows('header_carousel') ): the_row();
// vars
$mastHeadImages = get_sub_field('mast_head_images');
?>
<h3 class="header-text tagline"></h3>
<h1 class="header-text"></h1>
<?php
if( $mastHeadImages ): ?>
<div class="cycle-slideshow carousel-container" data-cycle-fx="scrollHorz" data-cycle-timeout="0" data-cycle-prev="#prev" data-cycle-next="#next" data-cycle-caption=".carousel-counter" data-cycle-caption-template="<span class='bigger'>{{slideNum}}/ </span> <span class='smaller'>{{slideCount}}</span>">
<div class="cycle-caption"></div>
<?php $i = 0; ?>
<?php foreach( $mastHeadImages as $image ): $imageURL = $image['url']?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" class="carousel-container__img carousel-img-<?php echo $i; ?>" />
<?php $i++; endforeach; ?>
<div class="masthead_overlay"></div>
</div>
<div class="center carousel-control-container">
<a href="#" id="prev">
<span class="icon-arrow-left"></span>
</a>
<a href="#" id="next">
<span class="icon-arrow-right"></span>
</a>
<div class="carousel-counter">
</div>
</div>
<?php endif; endwhile; endif; ?>
</header>
<?php
/*
* Template Name: Updated Custom Homepage
*/
get_header(); ?>
<?php include('masthead.php'); ?>
<div id="main" role="main">
<?php if( have_rows('flexible_content') ): ?>
<?php while( have_rows('flexible_content') ): the_row();
// vars
$mainContentImage = get_sub_field('main_content_image');
$asideContentImage = get_sub_field('aside_content_image');
$mainContentText = get_sub_field('main_content_text');
$asideContentText = get_sub_field('aside_content_text');
$CTALink = get_sub_field('cta_link');
$CTAText = get_sub_field('cta_text');
?>
<main id="main-content-container">
<!-- main content start-->
<div class="main-content" style="background-image: url(<?php echo $mainContentImage['url']; ?>)">
<div class="main-content-text">
<h3>
<?php echo $mainContentText; ?>
</h3>
<p>
Sub Text
</p>
<?php if($CTALink) :?>
<a href="<?php echo $CTALink; ?>" class="main-cta-btn">
<?php echo $CTAText; ?>
</a>
<?php endif;?>
</div>
</div>
<!-- main content end -->
<!--Aside content start-->
<div class="aside-content" style="background-image: url(<?php echo $asideContentImage['url']; ?>)">
<h2 style="color: #fff;"><?php echo $asideContentText; ?></h2>
</div>
<!--Aside content end-->
</main>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php get_footer();?>
If I haven't provided enough info, let me know. This is just a local project.