Frage

I'm using the Flexible Content add-on for Advanced Custom Fields and having trouble formatting a simple button link in my template code.

Normally I'd use something like this...

<a class="button" href="<?php the_field('button-link'); ?>"><?php the_field('button-text'); ?></a>

...to output the following html:

<a class="button" href="http://url.com/the-link">The Text</a>

But I can't figure out how to adapt that to work within my flexible content template:

<?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;

?>

Any suggestions? Thanks in advance

War es hilfreich?

Lösung

For those who may find this helpful in the future, I adapted my code as follows:

<?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; ?>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top