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条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致