使用 wordpress magic fields 在幻灯片中的图像周围添加链接

发布于 2024-12-29 04:01:13 字数 388 浏览 0 评论 0原文

我设置了一个带有 Magic fields 的幻灯片,如下面的代码所示,但是 现在我需要每个图像都有一个单独的链接。我该如何设置? 我只是想不出如何将其添加到下面的代码中,我很感激 任何人都可以向我提供的任何帮助。

<div id="slider"> 
<?php 
    $images = getFieldOrder('slideshow_slide'); 
    if(is_array($images)){ 
        foreach($images as $image){ 
            echo get_image('slideshow_slide',1,$image); 
        } 
    } 
?> 
</div> 

I have a slideshow set up with Magic fields like the code below, but
now I need each image to have a seperate link. How can I set this up?
I just can't think how I can add this to the code below, I appreciate
any help anyone can offer me.

<div id="slider"> 
<?php 
    $images = getFieldOrder('slideshow_slide'); 
    if(is_array($images)){ 
        foreach($images as $image){ 
            echo get_image('slideshow_slide',1,$image); 
        } 
    } 
?> 
</div> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

青朷 2025-01-05 04:01:13

魔法场万岁! <3

MagicFields 中有两种获取图像的方法。

方法 1 将返回完整图像标签:

echo get_image('slideshow_slide');

方法 2 仅返回图像的 url:

echo get_image('slideshow_slide',1,1,0);

为了生成完整尺寸图像的链接,您需要使用第二种方法构建锚标记。也许是这样的:

$image_path = get_image('slideshow_slide',1,1,0);

echo '在此处插入链接文本或缩略图';

您可能需要修改上面的内容才能工作与您的 foreach 循环一起使用,但这就是基本思想。

更新:
这就是你需要做的。创建另一个可重复的文本字段,名为 image_url。该字段将保存您的图像的链接。每个图像都需要一个对应的 url。此循环应该执行您想要的操作:

if(is_array($images)){
foreach($图像作为$图像){
$image_url = get('image_url',1,$image);
回显“" 。 get_image('slideshow_slide',1,$image) 。 “”;
}
}

Hooray MagicFields! <3

There are two ways to get an image in MagicFields.

Method 1 will return a full image tag:

echo get_image('slideshow_slide');

Method 2 just returns the url of the image:

echo get_image('slideshow_slide',1,1,0);

In order to generate a link to your full-size image, you'll need to construct an anchor tag using the second method. Maybe something like this:

$image_path = get_image('slideshow_slide',1,1,0);

echo '<a href="' . $image_path . '">Insert link text or thumbnail here</a>';

You might need to modify the above to work with your foreach loop, but that's the basic idea.

Update:
Here's what you need to do. Create another duplicateable text field, called image_url. This field will hold the link for your image. Each image will need a corresponding url. This loop should do what you want:

if(is_array($images)){
foreach($images as $image){
$image_url = get('image_url',1,$image);
echo "<a href='" . $image_url ."'>" . get_image('slideshow_slide',1,$image) . "</a>";
}
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文