简体   繁体   中英

Wordpress loop not working properly in lightbox?

I am building a wordpress portfolio with custom post types. The page shows thumbnails of the images and when you roll over them you see the title, the excerpt and a link to see the content of the post in a lightbox. To get the lightbox I am using a plugin called Lightbox Plus ColorBox. For some reason the lightbox shows the content from the most recent post in every posts light box instead of showing the content relevant to the thumbnail clicked.

The website URL is http://www.ginahughes.co.uk

This is my page code:

<div id="portfolio">   

<div class="group">  

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>  

    <?php  
        $title= str_ireplace('"', '', trim(get_the_title()));  
        $desc= str_ireplace('"', '', trim(get_the_content())); 

    ?>     


            <div class="bp-wrapper">  
                <a title="<?=$title?>: <?=$desc?>" href="<?php the_permalink() ?>"><?php the_post_thumbnail('portfolio-thumb'); ?></a>

                  <div class="bp-post-details">
                      <a title="<?=$title?>: <?=$desc?>" rel="lightbox" href="<?php the_permalink() ?>">
                      <h4>
                          <a class="lbp-inline-link-1 cboxElement" href="#">
                              <?=$title?></a></strong></h4>
                      <p><?php print get_the_excerpt(); ?></p>
                      </a>



                  </div>

            </div> 
             <div style="display: none;">
            <div id="lbp-inline-href-1" style="padding:10px; ">
                <?php the_content(); ?>
            </div>
        </div> 








<?php endwhile; endif; wp_reset_query(); ?>

</div>  

</div>  

Replace your class and id to be dynamic something like

<div id="portfolio">   

<div class="group">  

    <?php 
$i=1;
if (have_posts()) : while (have_posts()) : the_post(); ?>  

    <?php  
        $title= str_ireplace('"', '', trim(get_the_title()));  
        $desc= str_ireplace('"', '', trim(get_the_content())); 

    ?>     


            <div class="bp-wrapper">  
                <a title="<?=$title?>: <?=$desc?>" href="<?php the_permalink() ?>"><?php the_post_thumbnail('portfolio-thumb'); ?></a>

                  <div class="bp-post-details">
                      <a title="<?=$title?>: <?=$desc?>" rel="lightbox" href="<?php the_permalink() ?>">
                      <h4>
                          <a class="lbp-inline-link-<?=$i?> cboxElement" href="#">
                              <?=$title?></a></strong></h4>
                      <p><?php print get_the_excerpt(); ?></p>
                      </a>



                  </div>

            </div> 
             <div style="display: none;">
            <div id="lbp-inline-href-<?=$i?>" style="padding:10px; ">
                <?php the_content(); ?>
            </div>
        </div> 








<?php $i++;endwhile; endif; wp_reset_query(); ?>

</div>  

</div> 

its might solve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM