2014-02-12 16 views
0

我對高級自定義字段使用彈性內容附加組件,並且無法格式化我的模板代碼中的簡單按鈕鏈接。WP:高級自定義字段 - 靈活的內容鏈接格式

通常我會用這樣的事情...

<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

對於那些誰可能會發現在未來這是很有幫助的,我適應我的代碼如下:

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