可能是返回了以下行:
have_rows(\'google_drive_links\')
但是,子字段没有返回任何内容?
$content = get_sub_field(\'google_link_name\');
$link = get_sub_field(\'google_link\');
也许在创建hr和ul之前,您可以对这两个进行额外检查?
if (get_sub_field(\'google_link_name\') && get_sub_field(\'google_link\')){
// Create the hr and ul
}
根据您希望hr和h3显示的位置,可能如下所示:
<?php if( have_rows(\'google_drive_links\') ): ?>
<?php while( have_rows(\'google_drive_links\') ): the_row();
// vars
$content = get_sub_field(\'google_link_name\');
$link = get_sub_field(\'google_link\');
if ($content && $link) : ?>
<hr />
<h3>Attachments</h3>
<ul class="google-drive-links">
<li class="google-drive-link-item">
<a target="_blank" href="<?php echo $link; ?>"><?php echo $content; ?></a>
</li>
</ul>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
如果有多行链接,应该可以添加计数器,以确保hr和标题只添加一次,例如:
<?php
$counter = 0;
if( have_rows(\'google_drive_links\') ): ?>
<?php while( have_rows(\'google_drive_links\') ): the_row();
// vars
$content = get_sub_field(\'google_link_name\');
$link = get_sub_field(\'google_link\');
if ($content && $link) :
$counter ++;
// If there is content and link, create hr and title for first item only, open ul and create li
if ($counter == 1) : ?>
<hr />
<h3>Attachments</h3>
<ul class="google-drive-links">
<?php endif; ?>
<li class="google-drive-link-item">
<a target="_blank" href="<?php echo $link; ?>"><?php echo $content; ?></a>
</li>
<?php endif; ?>
<?php
endwhile;
if ($counter > 0) : ?>
<!-- Close ul -->
</ul>
<?php endif; ?>
<?php endif; ?>