У меня есть ссылка, настроенная как массив, а не URL. Используя этот код:
<?php $link = get_sub_field('link');
if( $link ): ?>
<p><a class="button" href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>"><?php echo $link['title']; ?></a></p>
<?php endif; ?>
заголовок страницы ссылки отображается только на главной странице "зарегистрироваться". На других страницах и в других настраиваемых полях ссылка href заполняется, но заголовок не отображается.
https://sullivanlehdesigns.com/clients/andonix/testing/
Под карточкой должна быть ссылка под текстом.
Результаты дампа на внутренней странице:
array(3) {
["title"]=>
string(0) ""
["url"]=>
string(72) "https://sullivanlehdesigns.com/clients/andonix/sign-up-for-a-test-drive/"
["target"]=>
string(0) ""
}
и на домашней странице:
array(3) {
["title"]=>
string(24) "Sign up for a test drive"
["url"]=>
string(72) "https://sullivanlehdesigns.com/clients/andonix/sign-up-for-a-test-drive/"
["target"]=>
string(0) ""
}
код в шаблоне:
<?php // check if the nested repeater field has rows of data
if( have_rows('card_item') ):
// loop through the rows of data ?>
<section class="cards">
<?php while ( have_rows('card_item') ) : the_row(); ?>
<div class="card">
<?php $image = get_sub_field('image');
echo '<img src="' . $image['url'] . '" alt="' . $image['alt'] . '" />'; ?>
<h3><?php the_sub_field('title'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<?php $link = get_sub_field('link');
if( $link ): ?>
<p class="button"><a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>"><?php echo $link['title']; ?></a></p>
<?php endif; ?>
</div>
<?php endwhile; ?>
</section>
<?php endif; ?>