【问题标题】:Wordpress loop not working properly in lightbox?Wordpress 循环在灯箱中无法正常工作?
【发布时间】:2014-02-11 09:09:07
【问题描述】:

我正在构建一个带有自定义帖子类型的 wordpress 作品集。该页面显示图像的缩略图,当您滚动它们时,您会看到标题、摘录和一个链接,以便在灯箱中查看帖子的内容。为了获得灯箱,我使用了一个名为 Lightbox Plus ColorBox 的插件。由于某种原因,灯箱会在每个帖子灯箱中显示最新帖子的内容,而不是显示与点击的缩略图相关的内容。

网站网址是http://www.ginahughes.co.uk

这是我的页面代码:

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

【问题讨论】:

    标签: javascript jquery wordpress lightbox


    【解决方案1】:

    将您的类和 id 替换为动态的类似

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

    它可能会解决你的问题

    【讨论】:

    • 非常感谢!它现在显示相关的帖子内容。第一篇文章的 css 样式与后续文章略有不同,但我可能可以解决这个问题。非常感谢您的帮助。
    • (y).. 很高兴知道 :)。不要感谢我帮助 3 个人中的任何一个 ;) jai ho!!
    猜你喜欢
    • 1970-01-01
    • 2015-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    相关资源
    最近更新 更多