2017-08-11 150 views
0

我在我的主頁上有滑塊橫幅,不會鏈接到任何位置。我需要爲每個圖像添加鏈接的代碼是什麼?是否可以用以下代碼?:將鏈接添加到滑塊橫幅

Thank you! I need to add a different link to each banner. The banners are all going to the printf('<a href="yourlink.html"> link. What am I doing wrong? <div id="home"> 
    <div class="banner"> 
     <div class="banner-slider"> 
      <?php 
       if (!empty($options['slider_photo'])): 
        $slider_photos = explode(',', $options['slider_photo']); 

        foreach ($slider_photos as $k => $img): 
         printf('<a href="http://www.nemotile.com/tile/product/Handwritten/"><div class="banner-%d" style="background-image:url(%s)"></div></a>', $k, $img); 
        endforeach; 
       else: ?> 

        <a href="http://www.nemotile.com/tile/product/Handwritten/"><div class="banner-1"></div></a> 
        <a href="http://www.nemotile.com/tile/product/patchwork/"><div class="banner-2"></div> 
        <a href="http://www.nemotile.com/tile/product/BisazzaCementTiles/"><div class="banner-3"></div> 
        <div class="banner-5"></div> 
       <?php endif; ?> 
     </div> 

回答

0

您可以將此代碼更改爲以下摘錄。使用$ i,你可以加強你的URL數組,這應該給你一個通用的過程。我不確定你是如何獲得URL的,但這應該會讓你走上正確的道路。

<div class="banner"> 
 
    <div class="banner-slider"> 
 
     <?php 
 
     $urls = ['URL1', 'URL2', 'URL3', 'URL4']; 
 
     $i = 0; 
 

 
     if (!empty($options['slider_photo'])): 
 
      $slider_photos = explode(',', $options['slider_photo']); 
 

 
      foreach ($slider_photos as $k => $img): 
 
       printf('<a href="'.$urls[$i].'"><div class="banner-%d" style="background-image:url(%s)"></div></a>', $k, $img); 
 
       $i++; 
 
      endforeach; 
 
     else: ?> 
 

 
     <a href="http://www.nemotile.com/tile/product/Handwritten/"><div class="banner-1"></div></a> 
 
     <a href="http://www.nemotile.com/tile/product/patchwork/"><div class="banner-2"></div> 
 
      <a href="http://www.nemotile.com/tile/product/BisazzaCementTiles/"><div class="banner-3"></div> 
 
       <div class="banner-5"></div> 
 
       <?php endif; ?> 
 
    </div>

+0

謝謝!我需要爲每個橫幅添加不同的鏈接 –

+0

@SophieMitchell我已經爲您編輯了我的答案。 –

+0

工作。謝謝! –