使用 wordpress magic fields 在幻灯片中的图像周围添加链接
我设置了一个带有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
魔法场万岁! <3
MagicFields 中有两种获取图像的方法。
方法 1 将返回完整图像标签:
方法 2 仅返回图像的 url:
为了生成完整尺寸图像的链接,您需要使用第二种方法构建锚标记。也许是这样的:
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:
Method 2 just returns the url of the image:
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:
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>";
}
}