我使用AFC设置了Wordpress,并在页面上包含了've created two repeater fields, which I' ve . 在我的 Headers 中,我有一个转发器字段来显示轮播滑块 . 然后在 Headers 下方,我将我的页面内容包含在基本div中 . 我已将masthead.php添加到 get_header()
正下方的front-page.php中 .
出于某种原因,我只是在加载页面时才获得 Headers . Headers 标记下方的所有内容都会消失 . 但是,当我注释掉include函数以在我的front-page.php上拉入masthead.php时,我的主要内容会显示,但当然没有 Headers . 似乎存在某种冲突 .
我检查了我的php_error.log,它给了我这个:
PHP Parse错误:语法错误,第64行的[folder_structure] /masthead.php中的意外“<”
我检查并仔细检查了我的AFC字段,以确保它不是一个错字或我没有循环正确的事情 . 但它对我来说很好看 .
MASTHEAD.PHP如下
<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>
FRONT-PAGE.PHP如下
<?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();?>
如果我没有提供足够的信息,请告诉我 . 这只是一个本地项目 .
1 回答
因此,下面的代码实际上只是对代码的轻微修改 . 我注意到你将
get_sub_field('mast_head_images');
的值传递给foreach
,如果你想识别键然后使用图像对象的值,或者如果你使用gallery作为上述重复字段的字段类型(我怀疑是这种情况),这是正常的这里) .在这种情况下,此代码应该工作 .
但是,如果您使用库作为字段类型,那么我的假设是错误的,您的代码没有我能看到的错误 .