将 URL 链接添加到图像数组
我正在这个网站 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 ?>
I am working on this website poochclub.com and I want to add links to each of the top image slides on the home page.
My code calls the images through an array, so I wanted to know if it is possible to add specific links to the image slides so if you click on the image they go to a product page?
This is my code:
<?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 ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您也许可以使用关联数组,在这种情况下,您的代码将如下所示:
我很快就做到了这一点,所以我不确定是否有任何错误,但这是一般的想法。
You can perhaps use an associative array, In which case, your code would look something like this:
I did this pretty quickly, so i'm not sure if there's any errors, but that's the general idea.
像这样:
$yourLink
需要来自您的数据库或其他位置Like this:
$yourLink
Will need to come from from your database or other location