在下面的第36行,我有这一行:
<li>
<a class="fancybox" rel="<?php the_sub_field('project_name'); ?>-gallery" href="<?php the_sub_field('still'); ?>">
<img src="<?php the_sub_field('still'); ?>" alt="<?php the_sub_field('project_name'); ?>-still" height="71" width="100"></a>
</li>
我不确定为什么但是<?php the_sub_field('project_name'); ?>
没有打印。我猜它是因为它在while
循环内,位于另一个while
循环内。
现在php语句甚至没有打印出来,所以该行的输出如下所示:
<a class="fancybox" rel="-gallery" href="http://localhost/wordpress/wp-content/uploads/2014/12/17.jpg"><img src="http://localhost/wordpress/wp-content/uploads/2014/12/17.jpg" alt="-still" height="71" width="100"></a>
请注意-gallery
和-still
之前没有任何内容。同样在第17行,我在上面之前调用该语句,它打印正常:<div id="<?php the_sub_field('project_name'); ?>">
。所以这就是为什么我猜它与while
循环在另一个while
循环中的事实有关。
如何让<?php the_sub_field('project_name'); ?>
打印出来?
<div id="tabs">
<?php if(have_rows('project')): ?>
<ul>
<?php while( have_rows('project') ): the_row(); ?>
<li><a href="#<?php the_sub_field('project_name'); ?>"><?php the_sub_field('project_name'); ?></a></li>
<?php endwhile; ?>
</ul>
<?php while( have_rows('project') ): the_row(); ?>
<div id="<?php the_sub_field('project_name'); ?>">
<img class="project-background" src="<?php the_sub_field('background_image'); ?>" alt="<?php the_sub_field('project_name'); ?>-background" height="530" width="325">
<div class="project-trailer">
<iframe src="//player.vimeo.com/video/<?php the_sub_field('vimeo_id'); ?>?title=0&byline=0&portrait=0&color=ffffff" width="750" height="300" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
<div class="project-stills">
<h3>Stills</h3>
<?php
// check if the repeater field has rows of data
if( have_rows('stills') ):
// loop through the rows of data
while ( have_rows('stills') ) : the_row(); ?>
<li><a class="fancybox" rel="<?php the_sub_field('project_name'); ?>-gallery" href="<?php the_sub_field('still'); ?>"><img src="<?php the_sub_field('still'); ?>" alt="still" height="71" width="100"></a></li>
<?php endwhile;
else :
// no rows found
endif; ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
答案 0 :(得分:0)
<li>
<a class="fancybox" rel="<?php echo the_sub_field('project_name'); ?>-gallery" href="<?php echo the_sub_field('still'); ?>">
<img src="<?php echo the_sub_field('still'); ?>" alt="<?php echo the_sub_field('project_name'); ?>-still" height="71" width="100"></a>
</li>