【问题标题】:Link Image Thumbnail to the Same Image in a Slideshow in Different Page将图像缩略图链接到不同页面中幻灯片中的相同图像
【发布时间】:2014-03-17 09:31:11
【问题描述】:

我有一个砖石画廊,目前,如果您单击任何缩略图,它会链接到不同页面中的幻灯片,无论您单击哪个缩略图,幻灯片都会显示第一个图像。我想知道是否有办法让幻灯片以缩略图点击的图像开始。

我尝试了这篇文章,但似乎没有这样做。

Linking to specific headers on other pages

我是怎么做到的,

缩略图:

<a href="#the_slide">
            <div class="m_overlay"><div class="m_txt"><?php echo $image['title']; echo $image['caption'];?>"</div></div>
            <img src="<?php echo $image['url'];?>" title="<?php echo $image['title']; echo $image['caption'];?>" alt="<?php echo $image['alt']; ?>">
</a>

幻灯片中的图片

       <?php
        global $post;
        $parent_id = $post->post_parent;
        $parentlink = get_permalink($parent_id);
        $images = get_field('gallery', $parent_id);
        ?>


        <ul class="slideshow">

        <?php foreach( $images as $image ): ?>
        <li>
            <h2 class="slideshow_title"><?php echo $image['title'];?></h2>
        <table>
        <tr>
        <td>


            <div class="slideshow_image"><a name="the_slide"></a><img src="<?php echo $image['url'];?>" alt="<?php echo $image['alt']; ?>"></div>
        </td>
        </tr>
        </table>
        </li>
        <?php endforeach; ?>
        </ul>

感谢您的帮助!

【问题讨论】:

  • 幻灯片是您制作的吗?或者它是一个插件?如果有,是什么插件?
  • 我正在使用 jQuery Cycle
  • 向我们展示代码...&lt;a name="the_slide"&gt; 没有任何意义。
  • jQuery Cycle 本身并不支持这一点。您可以使用 $_GET 变量更改将图像回显到页面中的顺序。
  • @David:你能详细说明一下吗?我对PHP真的不熟悉。

标签: javascript jquery html css image


【解决方案1】:

我能想到的最好方法是使用 $_GET 变量来告诉您的页面首先回显哪个图像,因为您的插件本身不支持它。它看起来像这样:

在您的图库页面上,让幻灯片的链接包含一个名为“thumb”的 $_GET 变量,该变量存储您要首先显示的缩略图的 ID 号:

<a href="/slideshow/index.php?thumb=3"><img .../></a>

其中 3 代表第三个缩略图。

然后在您的幻灯片放映的 PHP 文件中,您可以更改回显顺序。在拇指索引处回显图像(零索引减一),然后是其余部分的 for 循环,跳过您已经回显的图像(您可以使用 continue; 执行此操作

<ul class="slideshow">

    <?php 
        $thumb = $_GET["thumb"];

        $firstImage = $images[$thumb-1];
        //echo first image here

        for($i = 0; $i < count($images); $i++): 

        if($i == ($thumb-1)) continue;
        $image = $images[$i];
    ?>
    <li>
        <h2 class="slideshow_title"><?php echo $image['title'];?></h2>
    <table>
    <tr>
    <td>


        <div class="slideshow_image"><a name="the_slide"></a><img src="<?php echo $image['url'];?>" alt="<?php echo $image['alt']; ?>"></div>
    </td>
    </tr>
    </table>
    </li>
    <?php endfor; ?>
</ul>

【讨论】:

  • “拇指”这个名字是怎么来的……?我需要在某处添加或定义它吗?
  • 我试过了,但是当我点击缩略图时它会出现内部服务器错误。
  • Thumb 是您在 URL 中定义的变量:index.php?thumb=3 将 thumb 定义为 3。您知道服务器错误来自哪一行吗?您有权访问日志吗?
  • 我确实想查看日志,但我不确定错误来自哪一行。你认为这与网站是用 Wordpress 构建的有关吗?
  • 它是用 Wordpress 制作的这一事实不应该有效果。服务器错误意味着在runtime 期间PHP 代码中存在错误。所以没有语法错误,但是运行有问题;我假设它是 for 循环。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多