我正在使用wordpress网站,我想知道是否有办法为每个flexslider图像添加一个链接,以便在点击时链接会将用户带到网站内的其他页面? 我一直在寻找几个小时没有运气的答案。这是代码,
<?php
/*
* Template Name: Home
*/
get_header(); ?>
<div class="content">
<?php $slides = carbon_get_post_meta($post->ID, 'slides', 'complex');
if($slides) : ?>
<div class="main-slider flexslider">
<ul class="slides">
<?php foreach($slides as $slide) :
if(empty($slide['image'])) {
continue;
} ?>
<li><img src="<?php echo assante_get_thumb_url($slide['image'], 690, 461); ?>" alt="" /></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
<?php get_footer(); ?>
答案 0 :(得分:3)
您可以将图像包装在链接中。像这样:
<div class="flexslider">
<ul class="slides">
<li>
<a href='linkto'><img src="slide1.jpg" /></a>
</li>
</div>
在main page中有一个例子(第二张图片)。
修改强>:
//Let's say you have this array:
<?php
$slides = array(
array('image' => 'slide1.jpg','link' => 'link1'),
array('image' => 'slide2.jpg','link' => 'link2')
);
?>
<ul class="slides">
<?php
foreach ($slides as $slide) :
if (empty($slide['image'])) {
continue;
}
?>
<li>
<a href="<?php echo $slide['link']?>"> //Now we have a 'link' key to match every slide.
<img src="<?php echo assante_get_thumb_url($slide['image'], 690, 461); ?>" alt="" />
</a>
</li>
<?php endforeach; ?>
</ul>