将 URL 链接添加到图像数组

发布于 2025-01-06 22:16:30 字数 584 浏览 5 评论 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 ?>

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心碎无痕… 2025-01-13 22:16:30

您也许可以使用关联数组,在这种情况下,您的代码将如下所示:

<?php 
        $images = array('welcome.png' => 'link1', 'christmas.png'=> 'link2') 
        //shuffle($images);
        $i = 0;
        foreach ($images as $key => $value): ?>
        <a href="<?php $value ?>"><img src="<?= $theme ?>/images/home/carousel-<?= $key ?></a>" />
    <?php $i++; endforeach ?>

我很快就做到了这一点,所以我不确定是否有任何错误,但这是一般的想法。

You can perhaps use an associative array, In which case, your code would look something like this:

<?php 
        $images = array('welcome.png' => 'link1', 'christmas.png'=> 'link2') 
        //shuffle($images);
        $i = 0;
        foreach ($images as $key => $value): ?>
        <a href="<?php $value ?>"><img src="<?= $theme ?>/images/home/carousel-<?= $key ?></a>" />
    <?php $i++; endforeach ?>

I did this pretty quickly, so i'm not sure if there's any errors, but that's the general idea.

戴着白色围巾的女孩 2025-01-13 22:16:30

像这样:

<?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 需要来自您的数据库或其他位置

Like this:

<?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 Will need to come from from your database or other location

假装爱人 2025-01-13 22:16:30
<?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 } ?>
<?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 } ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文