我正在使用高级自定义字段的灵活内容插件,并且无法在模板代码中格式化简单的按钮链接。
通常我会使用这样的东西......
<a class="button" href="<?php the_field('button-link'); ?>"><?php the_field('button-text'); ?></a>
...输出以下html:
<a class="button" href="http://url.com/the-link">The Text</a>
但我无法弄清楚如何使其适应我的灵活内容模板:
<?php
if( have_rows('sidebar-content') ):
while ( have_rows('sidebar-content') ) : the_row();
if( get_row_layout() == 'text-content' ):
echo '<div class="sidebar-text-content">';
the_sub_field('flexible-text-content');
echo '</div>';
elseif( get_row_layout() == 'quote' ):
echo '<blockquote>';
the_sub_field('quote-text');
echo '<span class="quote-source">';
the_sub_field('quote-source');
echo '</span>';
echo '</blockquote>';
elseif( get_row_layout() == 'images' ):
$image = get_sub_field('image');
echo '<img src="' . $image['sizes']['large'] . '" alt="' . $image['alt'] . '" />';
endif;
endwhile;
endif;
?>
有什么建议吗?提前致谢
答案 0 :(得分:0)
对于那些将来可能会觉得有用的人,我调整了我的代码如下:
<?php if( have_rows('sidebar-content') ): ?>
<?php while ( have_rows('sidebar-content') ) : the_row(); ?>
<?php if( get_row_layout() == 'text-content' ): ?>
<div class="sidebar-text-content">
<?php the_sub_field('flexible-text-content'); ?>
</div>
<?php elseif( get_row_layout() == 'quote' ): ?>
<blockquote>
<?php the_sub_field('quote-text'); ?>
<span class="quote-source">
<?php the_sub_field('quote-source'); ?>
</span>
</blockquote>
<?php elseif( get_row_layout() == 'images' ):
$image = get_sub_field('image');
echo '<img src="' . $image['sizes']['large'] . '" alt="' . $image['alt'] . '" />';
?>
<?php elseif( get_row_layout() == 'button' ): ?>
<a class="button" href="<?php the_sub_field('button-link'); ?>"><?php the_sub_field('button-text'); ?></a>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>