2012-02-17 143 views
0

我正在使用本网站poochclub.com,我想添加链接到主页上的每个热门图像幻灯片。添加链接到图像阵列的链接

我的代码通过一个数组调用图像,所以我想知道是否可以添加指向图像幻灯片的特定链接,所以如果您点击图像,他们会进入产品页面?

这是我的代码:

<?php 
       $images = array('welcome.png', 'christmas.png', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg'); 
       //shuffle($images); 
       $i = 0; 
       foreach ($images as $im): ?> 
       <img src="<?= $theme ?>/images/home/carousel-<?= $im ?>" /> 
      <?php $i++; endforeach ?> 
+0

你想添加的链接存储在哪里? – ppp 2012-02-17 21:54:34

+1

产品页面的链接是什么?只是将''换成'' – 2012-02-17 21:54:58

回答

0

像这样:

<?php 
      $images = array('welcome.png', 'christmas.png', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg'); 
      //shuffle($images); 
      $i = 0; 
      foreach ($images as $im): ?> 
      <a href="<?php $yourLink ?>"><img src="<?= $theme ?>/images/home/carousel-<?= $im ?></a>" /> 
     <?php $i++; endforeach ?> 

$yourLink将需要来自从数据库或其他位置

+0

如果'yourlink'存储在另一个数组中,该怎么办?说$ links = array('link1','link2'.. etc).. – ppp 2012-02-17 21:58:42

+0

@AnPel - 我在编辑你添加的评论。 :)你是对的,这一切都取决于来源。因为没有指定,所以上面的例子应该让OP开始 – 2012-02-17 22:00:26

+0

对于数组源,例如$ links,因为有一个计数器,可以这样做:“... – ppp 2012-02-17 22:03:17

0
<?php 
$images = array('welcome.png', 'christmas.png', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg'); 

$links= array('link0.html', 'link1.html', 'link2.html', 'link3.html', 'link4.html', 'link5.html', 'link6.html'); 

for ($i=0 ; $i<count($images) ; $i++) {?> 
    <a href="<?= $links[$i] ?>"><img src="<?= $theme ?>/images/home/carousel-<?= $images[i] ?>" /></a> 
<?php } ?>