douyi4297 2017-04-10 18:17
浏览 95
已采纳

在循环中显示特色图像URL

I have a problem trying to get the thumbnail URL of each post on the archive page. I used the basic technics but it always return the url of the first featured image of the page.

Here the part of the code of my template-parts/post/content/content.php

The goal of this is to open the featured image of each post on a lightbox. Here the link to the page : http://leos-sipek.thomasdesnoyers.com/category/divers-types-dune-ideographie-stochastique/peinture-sur-papier/metaplasme/

If you click on the second post it shows the featured image of the first post.

    <div class="post-thumbnail">
        <a rel="lightbox" data-gall="gall-frame" data-lightbox-type="inline" href="#inline-content">
            <?php the_post_thumbnail( 'twentyseventeen-featured-image' ); ?>
        </a>
    </div>

    <!-- Lightbox -->

    <div id="inline-content" style="display:none;">
            <?php if (has_post_thumbnail( $post->ID )) : ?>
            <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
            <div class="img-single" style="background-image: url('<?php echo $image[0]; ?>')"></div>
    </div>

Thanks

  • 写回答

3条回答 默认 最新

  • doudandui1592 2017-04-13 13:46
    关注

    Guys you pointed something right. Actually I was pointing the same url for each lightbox so it opened the same each time. I change the Href of each lightbox by the ID of each post and it works.

        <div class="post-thumbnail">
            <a rel="lightbox" data-gall="gall-frame" data-lightbox-type="inline" href="#<?php the_ID(); ?>">
                <?php the_post_thumbnail( 'twentyseventeen-featured-image' ); ?>
            </a>
        </div>
    
        <!-- Lightbox -->
    
        <div id="<?php the_ID(); ?>" style="display:none;">
                <?php if (has_post_thumbnail( $post->ID )) : ?>
                <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
                <div class="img-single" style="background-image: url('<?php echo $image[0]; ?>')"></div>
        </div>
    

    Thanks everyone for your help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog